skip to Main Content

Javascript – setTimeout not starting in js

I am trying to make stopwatch but setTimeout is not working as intended.when I press state button then only count variable changes and not according to setTimeout function. Here's my javascript code const hr_button = document.querySelector("#hr"); const min_button = document.querySelector("#min");…

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