How to use JavaScript scheduling methods with React hooks
At times, you may want to execute a function at a certain time later or at a specified interval. This phenomenon is called, scheduling a function call.
JavaScript provides two methods for it,
setInterval
setTimeout
Using these scheduling methods w...
blog.greenroots.info9 min read
In both cases we use this two lines
let currCount = countRef.current; setCounter(currCount => currCount + 1);why we use the same name for the function parameter inside the setCounter?
setCounter(currCount => currCount + 1);
I believed that adding an arrow function inside a setState will make the parameter the last value of the state thus unrelated with the countRef.current, and unrelated with the currCount, which is a local function variable.