const tick = () => {
setCount(prevCount => prevCount+1);
// setCount(count+1);
}
My question is from where prevCount variable is getting it's initial value? How the expression supplied to setCount() is working?
I have created a react example to explain.
React js example, please refer tick function in interval.jsx component.
Update: As per a comment by Dennis Vash on my question I am supplying callback function to setCount() then Why it does not work if I write it like this?
const tick = () => {
setCount(updateCount(count))
// setCount(count+1);
}
const updateCount = (myCount) => {
return myCount + 1;
}