我正在使用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] 删除。
我来说两句