React Strict Mode & Development Warnings – Debugging Best Practices
When developing React applications, catching potential issues early can save you hours of debugging later. That’s exactly what React Strict Mode helps you do. It’s a development-only tool that highlights potential problems, encourages best practices, and ensures your app is ready for future React updates.
Let’s explore what it is, how it works, and how to use it effectively in your React projects.
What is React Strict Mode?
React Strict Mode is a special feature in React that helps developers identify unsafe lifecycles, deprecated APIs, and unexpected side effects during development.
It doesn’t affect your production build — it only runs in development mode to make your code more reliable and future-proof.
You enable it by wrapping your app (or part of it) inside the <React.StrictMode> component.
Example – Enabling Strict Mode
In a typical React project (e.g., created using Create React App or Vite), Strict Mode is already enabled by default in your index.js file:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Here, React will run extra checks and issue warnings in the console if it detects potential problems.
What Strict Mode Checks For
React Strict Mode helps you identify:

- Unsafe Lifecycle Methods
- It flags legacy lifecycle methods like
componentWillMount,componentWillReceiveProps, andcomponentWillUpdate, which can cause bugs in async rendering.
- It flags legacy lifecycle methods like
- Side Effects in Render Phase
- It intentionally runs functions like
useEffect,useState, or class constructors twice (in development only) to help you detect side effects that shouldn’t run during rendering.
- It intentionally runs functions like
- Deprecated APIs or Methods
- It warns when your code uses outdated APIs that React plans to remove in the future.
- Unexpected State Mutations
- It ensures components are pure and predictable, warning you if state or props are mutated directly.
- Detecting Legacy Context API
- It alerts you if you’re still using the old context API, recommending migration to the modern
React.createContext()approach.
- It alerts you if you’re still using the old context API, recommending migration to the modern
Why React Runs Some Functions Twice
You might notice that certain functions (like useEffect or useState initializers) seem to run twice in development mode.
Don’t panic — this is intentional.
React does this to help you identify side effects that run during rendering, which can cause bugs when components are mounted or re-rendered.
Example:
useEffect(() => {
console.log("Effect ran!");
fetch("/api/data"); // side effect
}, []);
In Strict Mode, the log may appear twice in the console — but in production, it will only run once.
Debugging with Development Warnings
When React detects a potential issue, it shows warnings in the browser console — not errors, so your app still runs.
Common warnings include:
- Missing
keyprops in lists - Mutating state directly
- Using deprecated lifecycle methods
- Side effects in render
- Using non-serializable values in state
Best Practices for Debugging with Strict Mode
Here are some practical tips to get the most out of Strict Mode:
- Keep Strict Mode enabled throughout development.
- Resolve console warnings before building for production.
- Use functional components and hooks — they work best with Strict Mode.
- Avoid side effects inside
render()or outsideuseEffect(). - Use useEffect cleanup to prevent memory leaks.
- Test components independently to confirm that re-renders behave as expected.
- Leverage React DevTools for inspecting component hierarchies and state updates.
Benefits of React Strict Mode
- Improves Code Quality – Encourages clean, predictable logic
- Future-Proofs Your App – Prepares your code for upcoming React versions
- Detects Common Bugs Early – Prevents runtime issues
- Encourages Best Practices – Promotes modern React patterns
- Works Seamlessly with Hooks – Ensures effects are safe and isolated
Important Notes
- Strict Mode only runs in development, not production — so no performance penalty for users.
- You can wrap only specific parts of your app inside
<React.StrictMode>to test them individually.
Example:
function App() {
return (
<><React.StrictMode>
<UserProfile />
</React.StrictMode>
<LegacyComponent /> {/* Not inside StrictMode */}
</>
);
}
