Seeing Double Fetches as a Feature, Not a Bug
You'll learn why StrictMode's double-mounting behavior is actually helping you catch production bugs early.
The Mental Shift
When you first see your fetch fire twice in development, it feels like React is broken or wasteful. But here's the perspective shift: if your effect breaks under double-mounting, it will also break in production when users navigate away and come back to your component.
Think of StrictMode like a smoke detector. It's annoying when it beeps during cooking, but it's doing exactly what you want—alerting you to a problem before there's a real fire. The double-fetch isn't creating bugs; it's revealing bugs that were always there.
The Real-World Scenario
Imagine a user searches for "cats", your component mounts and fetches cat data. They click to a detail page (component unmounts), then hit the back button (component remounts). Without proper cleanup (AbortController or ignore flags), you might:
- Show stale data from the first mount
- Have memory leaks from uncleared listeners
- Set state on unmounted components
- Display the wrong results due to race conditions
StrictMode simulates this mount-unmount-remount cycle on every mount in development. It forces you to handle the back-button case upfront, not after user reports.
Why This Matters
The double-fetch isn't a bug to work around—it's a test of your effect's resilience. If your effect passes the StrictMode test (mount → cleanup → mount again), it will handle real-world navigation patterns gracefully.
Key Takeaway: StrictMode's double-mounting is a feature that exposes cleanup bugs early; effects that survive it will work correctly when users navigate back to your component in production.