zoukankan      html  css  js  c++  java
  • PropTypes.element和PropTypes.node的区别

    PropTypes.element:指React Element,即React.CreateElement生成的元素,React.CreateElement可以用jsx语法糖表示:

    <MyButton color="blue" shadowSize={2}>
      Click Me
    </MyButton>

    编译后为:

    React.createElement(
      MyButton,
      {color: 'blue', shadowSize: 2},
      'Click Me'
    )
    

    因此PropTypes.element可以为以下类型:string | 组件实列(组件标签,例如上面的<MyButtom>)

    PropTypes.node:指React Node,任何可被渲染的元素,包括ReactChild | ReactFragment | ReactPortal | 字符串 | 数字 | 布尔值 | null | undefined | 数组;

    摘自大神的回答:

    Quote @ferdaber: A more technical explanation is that a valid React node is not the same thing as what is returned by React.createElement. Regardless of what a component ends up rendering, React.createElement always returns an object, which is the JSX.Element interface, but React.ReactNode is the set of all possible return values of a component.

    • JSX.Element -> Return value of React.createElement
    • React.ReactNode -> Return value of a component
  • 相关阅读:
    损失函数
    DPM 目标检测1
    编程题
    枚举型和元类
    python 多继承
    网络基础Cisco路由交换一
    网络基础tcp/ip协议五
    网络基础tcp/ip协议四
    网络基础tcp/ip协议三
    网络基础tcp/ip协议二
  • 原文地址:https://www.cnblogs.com/94pm/p/11688918.html
Copyright © 2011-2022 走看看