React 18 strict mode causing component to render twice [duplicate]

React StrictMode calls all Effects twice to make sure their cleanup/unmount handlers work as intended. You may need to change your effects accordingly, even if they have an empty dependency list and would normally not unmount before the site is closed.

Note, this only happens in Strict + development mode. In a production build, effects will only be called once and when their dependencies change.

Fore more context, see https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state

Leave a Comment