9
我想将React组件作为输入prop传递给另一个React组件。我试图引用它作为React.Component < *,*,*>但是当我在渲染方法中使用传递的组件时,我得到一个错误。这是我写出我的流程代码的方式。在将组件作为道具传递时在组件中键入React组件
/* @flow */
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
const Input = props => <div>Yo</div>
type DefaultProps = {
InputComponent: Input
};
type Props = {
InputComponent: React.Component<*, *, *>
};
class App extends Component<DefaultProps, Props, void> {
static defaultProps = {
InputComponent: Input
};
props: Props;
render() {
const { InputComponent } = this.props
return (
<div>
<InputComponent />
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
)
但是在App渲染方法我得到的错误
React element `InputComponent` (Expected React component instead of React$Component)
我应该如何正确打字输入组件?
该示例似乎不再有效,并且我无法在文档中找到有关“ReactClass”的任何内容。这个问题可能适用于旧版本的流程吗? – fraxture
的确,看起来ReactClass被删除了:https://github.com/facebook/flow/commit/20a5d7dbf484699b47008656583b57e6016cfa0b#diff-5ca8a047db3f6ee8d65a46bba4471236L136 – thejohnbackes
现在看起来类型是React.ComponentType。下面是我想你可能称之为变更的文档:https://github.com/facebook/flow/commit/20a5d7dbf484699b47008656583b57e6016cfa0b#diff-5ca8a047db3f6ee8d65a46bba4471236L136 –
thejohnbackes