React.StrictMode is a development-only tool that helps you write cleaner and safer React apps.
React.StrictMode is a wrapper component that you can place around part (or all) of your app. Everything inside <React.StrictMode> ... </React.StrictMode> gets extra checks in development mode.
It helps you:
useEffect().Remember: users in production never see these extra checks — they are only for you, the developer.
Typically, you wrap your root application component with <React.StrictMode> in index.js (or main.jsx).
// index.js using React.StrictMode for development checks
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.StrictMode> wraps the <App /> component. React will now run additional checks for every component rendered under <App />.
componentWillMount or componentWillReceiveProps.ref instead of direct DOM access.React.createRef() or useRef().These warnings are not “errors” — they are React’s way of telling you that some parts of your code can be improved or modernized.
In React 18, components inside <React.StrictMode> are intentionally rendered twice in development (not in production). This helps catch side effects that are not pure or not idempotent.
// App.jsx showing double logging in StrictMode (development only)
import React, { useEffect } from "react";
function App() {
useEffect(() => {
console.log("✅ useEffect ran");
}, []);
console.log("? Component rendered");
return <h1>Hello StrictMode!</h1>;
}
export default App;
When this component is wrapped in <React.StrictMode>, you might see:
? Component rendered (printed twice)✅ useEffect ran (also printed twice)This happens only in development and only because of StrictMode’s extra checks. In the production build, the component renders normally and effects run once.
You do not have to wrap your entire app. You can also test only a specific subtree with React.StrictMode.
// index.js with StrictMode applied to only some components
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import LegacyWidget from "./LegacyWidget";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// LegacyWidget is rendered without StrictMode checks
ReactDOM.createRoot(document.getElementById("legacy-root")).render(
<LegacyWidget />
);
This pattern is useful when you are gradually migrating older code to follow modern React patterns.
<React.StrictMode> at the top level (usually in index.js).<React.StrictMode> in index.js.useEffect() that logs to the console and observe the double logs in development.React.StrictMode and see how the logs change.componentWillMount) and see what warnings appear, then fix them using modern APIs.Goal: Understand how React.StrictMode surfaces warnings, helps you detect potential issues early, and prepares your project for future React versions.