Skip to content

How to Fix React StrictMode Double-Rendering

DodaTech Updated 2026-06-26 1 min read

The Problem

In this quick-fix, you'll learn how to handle StrictMode intentional double-invocation of effects. This matters because StrictMode double-rendering catches side effects but confuses developers. In real-world applications, this pattern appears in identifying impure render functions and missing cleanup during development.

The Wrong Way

function App() {
  const [count] = useState(0);
  useEffect(() => {
    console.log('Effect ran');
    const interval = setInterval(() => console.log('Tick'), 1000);
  }, []);
  return <div>{count}</div>;
}
Effect ran Effect ran Tick Tick -- interval leak undetected

The Right Way

function App() {
  const [count] = useState(0);
  useEffect(() => {
    console.log('Effect ran');
    const interval = setInterval(() => console.log('Tick'), 1000);
    return () => { console.log('Cleanup'); clearInterval(interval); };
  }, []);
  return <div>{count}</div>;
}
Effect ran Cleanup Effect ran Tick Tick -- cleanup verified

Prevention

  • Always provide cleanup functions in useEffect
  • Dont rely on effects running once in dev
  • Make render functions pure
  • StrictMode only affects development

FAQ

### Why does StrictMode double-render??

React intentionally double-invokes render and effects to detect impure components and missing cleanups. Mounts unmounts then remounts.

Does StrictMode affect production??

No. StrictMode checks only run in development. Production builds make StrictMode a no-op.

How to run side effect only once??

Make effect idempotent. If cannot run twice safely it likely has missing cleanup. Use ref to track init as last resort.

This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro