React
Components, hooks, state management, and rendering
How-To Guides
Why useEffect runs twice in development and how to write it so that's fine
In development, Strict Mode mounts each component, unmounts it, and mounts it again, so an effect runs, cleans up, and runs once more.
useEffectstrict-modecleanupsubscriptionsdevelopment
Reset a component's state when the thing it shows changes
Give the component a key tied to its subject.
keystateresetremountforms
Update state from its previous value without losing updates
Pass a function to the setter when the new value depends on the old one.
useStatesetStateupdaterbatchingclosures