Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

How to correctly use HOC with two kinds of props

$
0
0

I'm having trouble figuring out how to apply HOCs to this situation. I want to wrap existing components, since they all do very similar things. Here's a simplified version my current setup:

function CreateComponentHere(props: BaseProps): JSX.Element {    return <ComponentWithComponentProps />;}export const NewComponent = withBaseProps<BaseProps>(CreateComponentHere);

-

export function withBaseProps<T extends BaseProps>(WrappedComponent: ComponentType<ComponentProps>) {    return (props: T): JSX.Element => {        return (<WrappedComponent componentprop={props.valueForComponentProp}/>        );    }}

With this I finally have the componentprop pointing to the right type (ComponentProps) while the standard props are of type BaseProps.However, right now typescript complains about:export const NewComponent = withBaseProps<BaseProps>(CreateComponentHere); with the error:

Argument of type '(props: BaseProps) => Element' is not assignable to parameter of type 'ComponentType'.

What am I missing?


Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>