react 不使用严格模式_React严格模式

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控制台中打印有用的警告。

翻译自: https://flaviocopes.com/react-strictmode/

react 不使用严格模式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值