Skip to main content

reactStrictMode

很高兴知道:自 Next.js 13.5.1 起,严格模式默认为 trueapp 路由,因此上述配置仅对 pages 是必要的。你仍然可以通过设置 reactStrictMode: false 来禁用严格模式。

¥Good to know: Since Next.js 13.5.1, Strict Mode is true by default with app router, so the above configuration is only necessary for pages. You can still disable Strict Mode by setting reactStrictMode: false.

建议:我们强烈建议你在 Next.js 应用中启用严格模式,以便更好地为 React 的未来做好准备。

¥Suggested: We strongly suggest you enable Strict Mode in your Next.js application to better prepare your application for the future of React.

React 的 严格模式 是仅开发模式的功能,用于高亮应用中的潜在问题。它有助于识别不安全的生命周期、旧版 API 的使用以及许多其他功能。

¥React's Strict Mode is a development mode only feature for highlighting potential problems in an application. It helps to identify unsafe lifecycles, legacy API usage, and a number of other features.

Next.js 运行时符合严格模式。要选择严格模式,请在 next.config.js 中配置以下选项:

¥The Next.js runtime is Strict Mode-compliant. To opt-in to Strict Mode, configure the following option in your next.config.js:

module.exports = {
reactStrictMode: true,
}

如果你或你的团队尚未准备好在整个应用中使用严格模式,那也没关系!你可以使用 <React.StrictMode> 逐页增量迁移。

¥If you or your team are not ready to use Strict Mode in your entire application, that's OK! You can incrementally migrate on a page-by-page basis using <React.StrictMode>.