In my react-native project using expo, I am incorporating typescript for better type checking.
With the use of react-navigation in my project, I can define navigationOptions
on my screens and access the navigation
prop.
My current focus is on strongly typing these options to receive helpful hints about available properties to set.
interface NavStateParams {
someValue: string
}
interface Props extends NavigationScreenProps<NavStateParams> {
color: string
}
class Screen extends React.Component<Props, any> {
// It works as expected
static navigationOptions: NavigationStackScreenOptions = {
title: 'ScreenTitle'
}
// This does not work
static navigationOptions: NavigationStackScreenOptions = ({navigation, screenProps }) => ({
title: navigation.state.params.someValue
})
}
What is the most effective approach to handling react-navigation as props for components?