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

Should we and how to name react-navigation screen prop types?

$
0
0

According to the official documentation about type checking, we have to name our navigation prop type like this:

type HomeScreenNavigationProp = StackNavigationProp<StackParamList, 'Home'>;
type HomeScreenRouteProp = RouteProp<StackParamList, 'Home'>;

interface Props {
  navigation: HomeScreenNavigationProp,
  route: HomeScreenRouteProp,
}

And change Home by the each screen name.

But this can be easily simplified to this:

type Navigation = StackNavigationProp<StackParamList, 'Home'>;
type Route = RouteProp<StackParamList, 'Home'>;

interface Props {
  navigation: Navigation,
  route: Route,
}

Or even simpler, declaring type directly on the Props interface like this:

interface Props {
  navigation: StackNavigationProp<StackParamList, 'Home'>,
  route: RouteProp<StackParamList, 'Home'>,
}

With the same result.

Is there any technical reason to avoid what I am doing and name the prop types like described on the documentation?

If not, is there any convention about type naming with react-navigation and/or react-native?


Viewing all articles
Browse latest Browse all 6211

Trending Articles



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