I am so confused here with React useEffect Hooks with setTimeout.
but my code is rendering "I've rendered 2 times" instead of "I've rendered 1 time". And I have tried it in many code editors, and mine always shows 2..
My:
And the only way I can get it to render 1 is refactoring to this instead
useEffect(() => {
setTimeout(() => {
setCount(count + 1);
}, 1000);
}, []);
Could someone please explain to me why? Thanks for your help!
I am expecting my code to render the same result as the w3school example.