Course contentsShow
← React
Lesson 597 of 2,39616. useEffect for Data FetchingFree lesson

What StrictMode Does: Intentional Double-Mounting

React's StrictMode intentionally mounts components twice in development to surface side-effect bugs early.

What StrictMode Does: Intentional Double-Mounting

You'll learn why React deliberately mounts your components twice in development mode—and why that's actually helping you.

The Surprising Development Behavior

When you wrap your app in <React.StrictMode>, React intentionally mounts every component, unmounts it, then mounts it again—but only in development. This happens silently in the background.

Here's what the sequence looks like:

  1. Component mounts → useEffect runs
  2. Component unmounts → cleanup function runs
  3. Component mounts again → useEffect runs again

This doesn't happen in production. It's a developer tool, not a bug.

Why React Does This

StrictMode's double-mounting surfaces problems with your effects immediately rather than letting them hide until production. It's like a stress test for your cleanup logic.

Think of it like a fire drill: If your building evacuation plan only works when there's a real fire, you'll discover problems too late. By practicing repeatedly, you find what's broken early.

Specifically, double-mounting catches:

  • Missing cleanup functions (event listeners that pile up, timers that keep running)
  • Fetch requests that don't abort (race conditions waiting to happen)
  • Effects that assume they only run once (when they might run many times)
  • Subscriptions that leak (connections that never close)

What This Means for You

If you see your useEffect logs appearing twice in the console, or your fetch happens twice on mount—that's intentional. React is checking whether your cleanup works correctly.

The double-mount won't happen in production, but if your code breaks because of it, you have a real bug that could surface in production through remounting (navigation, conditional rendering, etc.).

Key Takeaway: StrictMode's double-mounting in development deliberately stress-tests your effect cleanup to catch bugs early—embrace it as a helpful debugging tool, not a nuisance.