Answer the question
In order to leave comments, you need to log in
How to get all props of a React component by its instance?
We have typescript and two components.
I want component 2 to require all the same values in props as component 1.
How I imagine it:
import {Button} from 'react-native';
const MyButton = (props: typeof Button) => {
return <Button title={props.title} onPress={props.onPress} style={{color:'#fff'}} />
}
Answer the question
In order to leave comments, you need to log in
import type {ComponentType} from 'react';
import {Button} from 'react-native';
type InferProps<Component> = Component extends ComponentType<infer Props> ? Props : never;
const MyButton = (props: InferProps<typeof Button>) => {
return <Button title={props.title} onPress={props.onPress} style={{color:'#fff'}} />
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question