reactjstypescriptnext.jslifecyclestrict-mode

Wrapping with React.StrictMode in Next.js


I have React.StrictMode set to true next.config.mjs of Next.js I am using for React project. Do I still wrap with <React.StrictMode> in the layout.tsx ? Do both serve the same purpose? I have page.tsx and layout.tsx in the Next.js project.


Solution

  • It depends on your purpose, in case you need to set strict mode to the entire application you can use the next.config.mjs file.

    or you need to specifically set the component to strict mode you can wrap the the component alone with <React.StrictMode>.