I have a utility function that accepts a class based React component as a parameter. What should I type this as?
function doSomething(id: string, component: ???) {}
If it is a functional component, you can try typing it as a FunctionComponent
on your function's parameter.
function doSomething(id: string, component: FunctionComponent) {
// do the rest
}
If it is a component class, you can try ComponentClass
instead.
function doSomething(id: string, component: ComponentClass) {
// do the rest
}
function doSomething(id: string, component: ReactNode) {}
It's the most suitable type
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.