Page 1 of 1

Predict the output of the below code snippet when start button is clicked. const AppComp = () => { const counter = useRe

Posted: Fri May 20, 2022 9:55 am
by answerhappygod
Predict The Output Of The Below Code Snippet When Start Button Is Clicked Const Appcomp Const Counter Usere 1
Predict The Output Of The Below Code Snippet When Start Button Is Clicked Const Appcomp Const Counter Usere 1 (55.78 KiB) Viewed 41 times
React Js questions
Predict the output of the below code snippet when start button is clicked. const AppComp = () => { const counter = useRef(0); const startTimer = () => { setInterval(( => { console.log('from interval, ', counter.current) counter.current += 1; }, 1000) } return <div>{counter.current}</div> <button onClick={startTimer}>Start</button> a) Both console and dom will be updated with new value every second b) No change in console and dom c) Console will be updated every second, but dom value will remain at 0 d) Error