Why does my useEffect run twice in development?
Ask QuestionAsked 5 days agoViewed 1.4k times
I see my effect fire twice on mount. Is something wrong with my code, or is this expected behavior in React 18?
PN
2 Answers
- ✓✓ Accepted answer
React 18 StrictMode intentionally double-invokes effects in development to surface missing cleanup. Your code is fine — production mounts once.
MW It only happens in dev — production mounts once. Make sure your effects clean up after themselves and you can ignore the double fire.
SA