4
我如何验证提供的道具是一个组件类(不是实例)?React propTypes组件类?
例如
export default class TimelineWithPicker extends React.PureComponent {
static propTypes = {
component: PropTypes.any, // <-- how can I validate that this is a component class (or stateless functional component)?
};
render() {
return (
<this.props.component {...this.props} start={this.state.start}/>
);
}
}
也可以使用'oneOfType'为不同的类型:'PropTypes.oneOfType([...])' – btzr
这不是一个实例?我认为''(又名'React.createElement(Foo,null)')是一个反应元素,而我想检查原始'Foo'。 –
mpen
不能:)有一个单独的PropType。 –