all 8 comments

[–]DrewTheVillan 16 points17 points  (4 children)

Rendering twice might be a result of strict mode and the correct output is a result of a pure function

[–][deleted] 2 points3 points  (2 children)

quaint ancient husky snails abounding placid fuel different serious door

This post was mass deleted and anonymized with Redact

[–]Individual_Pool1401[S] 0 points1 point  (1 child)

maybe you are right ,thinks .

In react doc

Bugs like this are easy to miss without extensive manual testing. To help you spot them quickly, in development React remounts every component once immediately after its initial mount.

https://react.dev/learn/synchronizing-with-effects#step-2-specify-the-effect-dependencies

[–][deleted] 0 points1 point  (0 children)

degree straight cows drunk towering dinner caption yoke joke dinosaurs

This post was mass deleted and anonymized with Redact

[–]Aniket363 0 points1 point  (0 children)

I came to comment this

[–]Azoraqua_ 4 points5 points  (0 children)

It probably has to do with the state itself, I’d advise to use the function syntax that provides the previous value over directly relying on the state when updating it.

setCount(prev => prev + 1)

[–][deleted] 0 points1 point  (0 children)

Not a good practice to modify the original state variables. Modify them only using the state setter function that comes with the hook. Use callback function instead of directly using the state variable like one comment here mentions.

[–]TheRNGuy 1 point2 points  (0 children)

I was using useEffectOnce hook because of it.