useEffect(() => {
let interval = null;
if (isOn) {
interval = setInterval(() => {
counting();
}, 1000);
} else {
clearInterval(interval);
}
return () => clearInterval(interval);
}, [isOn, currentTimeMs]);
const counting = () => {
setCurrentTimeMs(currentTimeMs + 1);
};
I thought the dependency of useEffect only accepted variables, but it also asks me to put a function that's a const? Why is that? Is that an error with webpack or something?
React Hook useEffect has a missing dependency: 'counting'. Either include it or remove the dependency array react-hooks/exhaustive-deps
I also am getting another warning:
The 'counting' function makes the dependencies of useEffect Hook (at line 39) change on every render. Move it inside the useEffect callback. Alternatively, wrap the 'pace' definition into its own useCallback() Hook react-hooks/exhaustive-deps
I thought I was already calling inside the useEffect callback. Can someone explain? The documentation doesn't say much about useEffect and its callback.