Referencing outdated state in React useEffect hook
I tried to do the same with the useEffect hook, but it seems state is not correct in the return function of useEffect. The reason for this is due to closures. A closure is a function’s reference to the variables in its scope. Your useEffect callback is only ran once when the component mounts and … Read more