Skip to content
Preptima
easyConceptEntryMid

Why does my useEffect run twice on mount?

React useEffect runs twice on mount in development when Strict Mode deliberately runs one extra setup-cleanup-setup cycle. It does not happen in production builds, and the fix is to write the cleanup the effect was missing rather than to guard the effect or remove Strict Mode.

5 min readUpdated 2026-08-15

Answer

Short answer

React useEffect runs twice on mount in development when the component is inside <StrictMode>. React intentionally performs a setup-cleanup-setup cycle to expose effects that do not clean up subscriptions, timers, listeners, or in-flight requests. It does not happen in production; the interview answer is to make the effect safe to run twice, not to hide the second run with a ref guard.

Was this answer helpful?

Likely follow-ups

  • How would you cancel an in-flight fetch in the cleanup function, and what happens to the rejected promise?
  • When is an empty dependency array the wrong choice, and how do you tell?
  • Why did React 18 introduce this behaviour, and what future feature was it preparing for?
  • Which of this work belongs in an effect at all, versus in an event handler or a data-fetching library?

Related questions

Further reading

Related Topics