This is my state:
const [time, setTime] = useState(10)
And this is my handler:
const runTimer = () => {
useEffect(() => {
const interval = setInterval(() => {
console.log(time)
if (time > 0) {
setTime(time - 1)
} else {
console.log("End")
}
}, 1000);
return () => clearInterval(interval)
}, [])
}
My log:
9
9
9
9
9
.
.
.
Why setTime
doesn’t work ?
time
variable most increase per 1000 delay