type Props = {
Component: ???
}
const AnotherComp = ({Component}: Props) => (
<Component />
)
什麼是爲組件添加道具的正確方法?如何流動鍵入一個組件?
type Props = {
Component: ???
}
const AnotherComp = ({Component}: Props) => (
<Component />
)
什麼是爲組件添加道具的正確方法?如何流動鍵入一個組件?
您要找的類型叫做ReactClass
。任何組件的類型將是ReactClass<any>
。
type FunctionComponent<P> = (props: P) => ?React$Element<any>;
type ClassComponent<D, P, S> = Class<React$Component<D, P, S>>;
type Component<D, P, S> = ClassComponent<D, P, S> | FunctionComponent<P>;
type Props = {
Component: Component<void, {}, void>
};
type Props = {
Component: React.Component<*>
};
class React.Component<P = {}, S = {}>
interface React.Component<P = {}, S = {}>
'ReactClass <*>'只是一個小更安全(如果這與使用情況符合) – inlinestyle
'ReactClass <*>'如果將其用作許多不同組件的類型,可能會造成一些麻煩。例如,作爲從一個條件分支返回'Foo'和從另一個分支返回'Bar'的返回類型。 Flow將無法弄清''Foo |應該是什麼' Bar' –