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

Preferred TypeScript signatures for functional components in ReactNative?

$
0
0

I'm having trouble following the current views on the best practice for typing functional React Native components in TypeScript. I find many posts and threads that seem to start with one view and then over time drift to another, without clear consensus.

Is there a current view on this? For example are any of the following preferred, or something else entirely?

// Version ONE (makes most "sense" to me)const MyComponent = (props: MyComponentProps): JSX.Element => {    return (         //... some JSX    )}
// Version TWO (makes props a PropsWithChildren<MyComponentProps>?)const MyComponent: FC<MyComponentProps> = (props) => {    return (        //... some JSX    )
// Version THREE (what I have in older examples I've done, but I don't know why)const MyComponent: FC<MyComponentProps> = (props): ReactElement => {    return (        //... some JSX    )

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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