4

I have a prop that changes when I update the state. How do I update my initial params when passing data to a screen?

props.authMsg gets updated, but not the initial param

<Stack.Screen initialParams={{authMsg: props.authMsg}} name="Login" component={Login} />

The param value stays the same.

<Text>{props.route.params.authMsg}</Text>

1 Answers1

3

The initial params will never change after initialization. What you can do is create a context in the component where you have the state with the help of the useContext hook and pass the value down so it will be accessible to any children of that component.

https://reactjs.org/docs/hooks-reference.html#usecontext

Cristian
  • 281
  • 2
  • 11