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

TypeScript Property 'navigation' is missing in type but required in type 'Props' React Native

$
0
0

In a React Native App, I understand that when you pass your RootNavigator inside createAppContainer and export it, the navigation prop is implicitly made available in all child components.

export default createAppContainer(AppNavigator);

I have this component that is supposed to navigate to another screen using the navigation prop. I defined an interface for the props of this component like this:

props interface for ComponentA:

interface Props {
  count: number;
  navigation: NavigationStackProp<{quizId: number}>;
}

Now I render ComponentA like this:

...
render() {
    return (
        <ComponentA count={0} /> // TypeScript screams here that I am not passing the navigation props
    );
}

If I pass the navigation prop with ComponentA like this:

<ComponentA count={0} navigation={props.navigation} />

TypeScript is satisfied.

My question therefore is, do I have to pass navigation prop explicitly like this? It doesn't feel right to me. Is there a way I can suppress TypeScript warnings for this particular situation.

I am new to TypeScript so this might be something trivial but I will appreciate any help.

Thanks


Viewing all articles
Browse latest Browse all 6211

Trending Articles



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