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
  • 相关阅读:
    XMPP核心协议客户端
    平安中国
    读写XML的API们
    IM只是可以用来玩的东西
    再骂自己一句
    淡定
    自己打造SAX和DOM Parser
    Nickel Instant Messeging System
    XMPP RFC阅读笔记(二)
    think in java 笔记
  • 原文地址:https://www.cnblogs.com/94pm/p/11688918.html
Copyright © 2011-2022 走看看