react 不使用严格模式
You can use the React.StrictMode
built-in component to enable a set of checks that React performs and warns you about.
您可以使用React.StrictMode
内置组件来启用一组React执行并警告您的检查。
An easy way is to wrap the entire App component in <React.StrictMode></React.StrictMode>
in the index.js file:
一种简单的方法是将整个App组件包装在index.js文件的<React.StrictMode></React.StrictMode>
中:
import React from 'react'
import ReactDOM from 'react-dom'
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>
document.getElementById('root')
You can also use it by wrapping one or more components of your app:
您还可以通过包装应用程序的一个或多个组件来使用它:
import React from 'react'
class Hello extends React.Component {
render() {
return (
<div>
<React.StrictMode>
...
</React.StrictMode>
<div>
)
}
}
One of the main use cases of this component is to be used as an automated best practices, potential problems and deprecations check.
该组件的主要用例之一是用作自动化的最佳实践,潜在问题和弃用检查。
It can’t catch all, but you have lots of nice checks here that can help you fix the low-hanging fruits.
它并不能解决所有问题,但是您在这里可以进行很多不错的检查,可以帮助您解决难以实现的目标。
Introduced in React 16.3 in March 2018, it has zero impact in production, so you can always leave the component in the codebase. Used in development it will print useful warnings in the browser JavaScript console.
它于2018年3月在React 16.3中引入,对生产没有任何影响,因此您始终可以将组件保留在代码库中。 用于开发中时,它将在浏览器JavaScript控制台中打印有用的警告。
react 不使用严格模式