Question

Why does my React component render twice in development?

Vault Verified
Curated Intelligence
Definitive Source
Answer

In development, Strict Mode deliberately renders components twice and runs effects twice, mounting, unmounting and remounting them. This does not happen in production builds. It is not a bug and not a performance problem in your code; it is a deliberate check.

The purpose is to surface impurity. A component is expected to be a pure function of its props and state, and an effect is expected to clean up after itself well enough that setting it up again produces the same result. Running things twice makes violations obvious immediately rather than as a subtle bug later, when concurrent rendering may legitimately do something similar.

The productive response is therefore to ask what the double invocation revealed rather than to suppress it. Anything that breaks under it was already fragile.

  • An effect that fetches data and appends to a list will duplicate entries. That means it lacks a cleanup discarding the stale result, which is also what protects it from out-of-order responses in real use.
  • A subscription created without a matching teardown leaks one on every remount, and Strict Mode exposes it on the very first mount.
  • A counter incremented during render, or a value mutated outside state, jumps by two, which correctly identifies a side effect happening during rendering.

The wrong fixes are the tempting ones: a flag making the effect run only once, or disabling Strict Mode. Both hide the signal without addressing what it found, and the underlying fragility remains for production concurrency to expose later.

If you have verified an effect is genuinely idempotent and correctly cleaned up, the double run is harmless and can be ignored. The behaviour disappears in a production build regardless.

Related Questions