如何在Flow中将道具类型定义为<div>?

布兰登

我正在使用ES6类编写React组件,我的一个props可以是astring或a <div>

我如何告诉Flow<div>可以接受?

现在:

import React from 'react'

type Props = {
  title: string,
  content: string | // <- or a div
};

export class ThisComponent extends React.Component {
// ...
甘蒂

您可以使用全局类型 React$Element

type Props = {
  title: string,
  content: string | React$Element<any>
};

div虽然您不能仅将AFAIK限制为

<ThisComponent title="mytitle" content={<div/>} /> // <= ok
<ThisComponent title="mytitle" content={<a/>} />   // <= ok as well

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章