skip to Main Content

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!

2

Answers


  1. 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
      ...
    }
    
    Login or Signup to reply.
  2. you can get navigation like this:

    const { DIC, navigation } = props;

    navigation comes within props.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search