In a react-native child-component, I need to read both parent-props and navigation.
I use this code in parent to pass DIC-props to child, which works just fine:
...
<Stack.Screen name="SignIn>
{(props) => <SignIn {...props} DIC={DIC} />}
</Stack.Screen>
...
In Child comp. I get that prop (DIC) like this, so far all fine:
const SignIn = (props) => {
const { DIC } = props
...
}
But in Child I need now to get navigation from props too, but this does not work (navigation appears as an empty object)
const SignIn = (props, {navigation}) => {
const { DIC } = props
...
Can someone see what am I doing wrong? How can I get both specific props AND navigation? Thx!
CodePudding user response:
I really recommend you using Typescript so that you can better understand what is happening under the hood. Anyway, as for your question, this should work for you:
const SignIn = ({ navigation, route }) => {
const DIC = route.params.DIC
...
}
CodePudding user response:
you can get navigation like this:
const { DIC, navigation } = props;
navigation comes within props.