skip to Main Content

Javascript – Why does child component re-renders even if useMemo is used

const Parent = () => { let [hitCounter,setHitCounter] = React.useState(0); let [clickCounter,setClickCounter] = React.useState(0); const data= React.useMemo(() => { console.log("in useMemo") return hitCounter },[hitCounter]); return( <> <Child hitCounter={data}/> <input type="button" onClick={() => setHitCounter(hitCounter + 1)} value="Hit me"/> {hitCounter} <div><input type="button"…

VIEW QUESTION
Back To Top
Search