Sling Academy
Home/Next.js/Next.js: How to Disable/Enable React Strict Mode

Next.js: How to Disable/Enable React Strict Mode

Last updated: January 14, 2023

React Strict Mode is a tool that runs in development mode only. It checks and highlights potential issues in your application, such as unsafe lifecycles, legacy API usage, etc. In Next.js, React Strick Mode is turned on by default for the whole application. This is useful, but sometimes you may feel it is a little annoying (such as some repetitive warnings that overflow and mess up your console).

You can disable or enable React Strict Mode by opening your next.config.js file and setting the reactStrictMode option to false or true, respectively:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false, // React Strict Mode is off
}

module.exports = nextConfig

You can use React Strict Mode for a few individual components or pages by wrapping them with <React.StrictMode> and </React.StrictMode>, like this:

// Sling Academy
// pages/index.js

export default function Home(props) {
  return <div style={{ padding: 30 }}>
    <div>
      <Header />
      <React.StrictMode>
        <div>
          <ExampleComponent />
          <DummyComponent />
        </div>
      </React.StrictMode>
      <Footer />
    </div>
  </div>
}

You can find more detailed information about React Strict Mode in its official docs.

Hope this helps. Happy coding and have a nice day!

Next Article: Nest.js: How to Write Unit Tests with Jest

Previous Article: How to Dockerize a Next.js App for Production

Series: Next.js: Configuration & Deployment

Next.js

Related Articles

You May Also Like

  • Solving Next.js Image Component Error with CSS Classes
  • How to Use MUI (Material UI) in Next.js 14
  • Fixing Data Update Issues in Next.js Production
  • Fixing Next.js Undefined ENV Variables in Production Build
  • Solving Next.js SyntaxError: Unexpected token ‘export’
  • Next.js Error: Found Page Without a React Component as Default Export – How to Fix
  • Fixing Next.js Error: Blank Page on Production Build
  • Fixing Next.js Error when Importing SVGs: A Step-by-Step Guide
  • Next.js Issue: useEffect Hook Running Twice in Client
  • Fixing ‘self’ is not defined error in Next.js when importing client-side libraries
  • How to Dockerize a Next.js App for Production
  • How to set up Next.js with Docker Composer and Nginx
  • Solving Next.js CORS Issues: A Comprehensive Guide
  • Fixing Next.js Hydration Mismatch Error in Simple Ways
  • Next.js Error: Cannot use import statement outside a module
  • Next.js: How to Access Files in the Public Folder
  • Fixing Next.js Import CSS Error: A Simple Guide
  • Fixing LocalStorage Not Defined Error in Next.js
  • Fixing Next.js Error: No HTTP Methods Exported