enter image description hereIn console, i am able to see the output, but on screen, it's not coming. How to input the string from user on input box, then show the results on screen? Is something wrong with the logic? Is there any better method?
import React, { useState } from 'react'
const CharCount = () => {
const [data, setData] = useState([])
const [print, setPrint] = useState(false)
const count= (value)=>{
const result = [...value].reduce((a, e) => { a[e] = a[e] ? a[e] + 1 : 1; return a }, [])
console.log(result, typeof(result))
return result
}
const getData=(e)=>{
setData(e.target.value)
setPrint(false)
}
return (
<div>
<input type="text" value={data} onChange={getData}/>
<button onClick={()=>setPrint(true)}>CLICK!</button>
{
print ? count(data):"error"
}
</div>
)
}
export default CharCount