5

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 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot, works like a charm. Still learning, but thank you for your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.