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

How to define this interface Props so that this Props contains all the attributes of the passed component

$
0
0
interface Props {    component: any;}function Example(props: Props) {    const {component: Component, children} = props    return <Component>{children}</Component>}

For example: the incoming component is TouchableOpacity in react-native,then the Example component automatically inherits all Props of TouchableOpacity.You can write like this and Typescript does not report errors:

<Example component={TouchableOpacity} onPress={handleSomePress} />

I am a newbie to TypeScript, this problem has bothered me for a long time.Looking forward to a perfect answer, pray.


Viewing all articles
Browse latest Browse all 6214

Trending Articles



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