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

ReactJs double render

When I try to refresh page it prints "1" twice. But I'm not using any useState or variable update or state change I think. Can you tell me where I'm wrong? import "./styles.css"; import React, { useState, useEffect, useRef }…

VIEW QUESTION

Reactjs – When does re-rendering actually happens?

Code: import { useState } from 'react'; export default function Counter() { const [number, setNumber] = useState(0); return ( <> <h1>{number}</h1> <button onClick={() => { setNumber(number + 1); setTimeout(()=>setNumber(number + 1),2000); setTimeout(()=>setNumber(number + 1),5000); }}>+3</button> </> ) } I went…

VIEW QUESTION
Back To Top
Search