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