【问题标题】:What exactly <React.StrictMode></React.StrictMode> component does?<React.StrictMode></React.StrictMode> 组件到底是做什么的?
【发布时间】:2020-05-17 05:06:08
【问题描述】:

我在 React 实践中发现了这个组件,但我不知道确切的行为是什么。

例如

const App = () => {
  return (
    <React.StrictMode>
      <div id="cool-attribute">
        <h1>Welcome to the Jungle!</h1>
        <SearchParams />
      </div>
    </React.StrictMode>
  );
};

【问题讨论】:

标签: javascript reactjs components jsx react-component


【解决方案1】:

首先你需要了解严格模式到底是什么。

严格模式是一种模式,在这种模式下,编译器会格外小心地处理一些额外的指令,不会自行消除静默错误,而是将它们抛出并在编码时施加更多限制。欲了解更多信息,请follow

React.StrictMode 是一回事,但在专门使用 React 时会提供更多限制。这里是综合guide

如果您期待 UI 中的某些内容,请停止,因为根据 React.StrictMode 文档:

StrictMode 不会呈现任何可见的 UI。它会为其后代激活额外的检查和警告。

【讨论】:

  • 哦,我明白了,我会检查文档,谢谢。
猜你喜欢
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 2015-08-06
  • 2013-09-02
  • 2014-01-02
  • 2013-10-10
  • 2017-05-08
  • 2022-01-20
相关资源
最近更新 更多