【问题标题】:What kind of checks and warnings does React.StrictMode activate?React.StrictMode 会激活什么样的检查和警告?
【发布时间】:2020-04-15 12:55:16
【问题描述】:

来自 React.StrictMode 和 React.Fragment 的 React 文档:
Both Fragment, StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants.

问题:React.StrictMode 对此代码激活了哪些检查和警告?

import React from 'react'

export default function About() {
    return (
        <React.StrictMode>
            <h1>About page</h1>
            <p>This is a text deescribing the About page</hp>
        </React.StrictMode>
    )
}

【问题讨论】:

  • 您是否阅读了从“StrictMode 当前有助于:” 开始的五点?您链接的文章的其余部分准确解释了它检测到的类型。
  • 哦,我的错!我没有通读这篇文章。谢谢@jonrsharpe

标签: javascript reactjs


【解决方案1】:

您链接的article 准确说明了它的帮助:

StrictMode 目前有助于:

  • 识别生命周期不安全的组件
  • 关于旧字符串引用 API 使用的警告
  • 关于不推荐使用 findDOMNode 的警告
  • 检测意外副作用
  • 检测旧版上下文 API

【讨论】:

    猜你喜欢
    • 2020-05-17
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 2012-07-20
    • 2017-10-14
    • 2018-04-27
    相关资源
    最近更新 更多