skip to Main Content

Reactjs – Why input value isn't changed when re-render is occured by object state update

I am studying React through React Offical Document. I have question about this challenge. (https://react.dev/learn/updating-objects-in-state#challenges https://codesandbox.io/s/rztj2r?file=/src/App.js&utm_medium=sandpack) Assume that the given code is executed as it is without modification, I understand why {player.score} is disappeared when re-render is occured by handleLastNameChange()…

VIEW QUESTION

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