什么是React.PropTypes.node的Flow等价物?

ahs*_*tro 14 javascript types reactjs flowtype

什么是Flow等价物React.PropTypes.node(即React可以呈现的任何东西,如果有的话?我是否必须自己创建它作为联合类型?

换句话说,这将取代???什么?

type Props = {
  children: ???,
}

const UselessComponent
  : (props: Props) => React$Element<*>
  = ({ children }) => (
    <div>
      {children}
    </div>
  )

UselessComponent.propTypes = {
  children: React.PropTypes.node.isRequired,
}
Run Code Online (Sandbox Code Playgroud)

小智 10

它看起来像它仍然是一个问题在这里.

根据该问题的讨论,在修复之前你应该做些什么:

type Props = {
  children?: React.Element<*>,
};
Run Code Online (Sandbox Code Playgroud)


Der*_*mer 9

对于flow> = 0.53的版本,请React.Node在props.children和您期望可渲染节点的任何位置使用新类型.

React.Node的定义可以用React.ChildrenArray粗略估计:

type Node = React.ChildrenArray<void | null | boolean | string |
number | React.Element<any>>;
Run Code Online (Sandbox Code Playgroud)

流量0.53中的反应类型进行了重大修改.有关如何迁移的更改和说明的摘要,请参见发行说明.该流程文档解释了如何详细使用.

例如:

import type { Node } from 'react';

type Props = {
  input?: Node,
}
Run Code Online (Sandbox Code Playgroud)