Reputation: 6894
type Props = {
Component: ???
}
const AnotherComp = ({Component}: Props) => (
<Component />
)
What's the proper way to add a prop for the component?
Upvotes: 2
Views: 3791
Reputation: 11
I think this is what you are looking for:
// 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 to documentation: https://flow.org/en/docs/react/types/#toc-react-element
Upvotes: 0
Reputation: 427
type Props = {
Component: React.Component<*>
};
class React.Component<P = {}, S = {}>
interface React.Component<P = {}, S = {}>
Upvotes: 0
Reputation: 1462
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>
};
Upvotes: 3
Reputation: 1937
The type that you're looking for is called ReactClass
. The type for any component would be ReactClass<any>
.
Check out this similar question: What type to use for things React can render?
Upvotes: 1