如何流式化一个Component?
How to flow type a Component?
type Props = {
Component: ???
}
const AnotherComp = ({Component}: Props) => (
<Component />
)
为组件添加 prop 的正确方法是什么?
您要查找的类型称为 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 = {}>
我想这就是您要找的:
// Component we want to pass as a prop
class MyComponent extends React.Component<{}> {}
type Props = {
Component: React.Element<typeof MyComponent>
}
const AnotherComp = ({ Component }: Props) => (
<Component />
)
Link 到文档:https://flow.org/en/docs/react/types/#toc-react-element
type Props = {
Component: ???
}
const AnotherComp = ({Component}: Props) => (
<Component />
)
为组件添加 prop 的正确方法是什么?
您要查找的类型称为 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 = {}>
我想这就是您要找的:
// Component we want to pass as a prop
class MyComponent extends React.Component<{}> {}
type Props = {
Component: React.Element<typeof MyComponent>
}
const AnotherComp = ({ Component }: Props) => (
<Component />
)
Link 到文档:https://flow.org/en/docs/react/types/#toc-react-element