-
-
Notifications
You must be signed in to change notification settings - Fork 72
How to have global state with recat-native-navigration #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey, thanks for trying. As the doc says, you need to find non-context solution. For example: |
Ah, if you like the state usage tracking feature in react-tracked, of course this: |
Thanks for the links! What I like about react-tracked is that I can easily use useState from individual components and have them stored in a global state. I've been digging around a bit and it seems that you can do it with a Proxy wix/react-native-navigation#4517 (comment) But not too sure how to do it with this lib. |
That workaround in the issue is a bit hacky. a) you don't need Proxy to make it work. b) it may only work because another screen rerenders with an updated value in the mutable global variable (if it works, it's because RNN behaves like that). c) you can't use function update.
If this is the goal, I'd encourage you to try https://github.com/dai-shi/react-hooks-global-state |
I tried zustand and it worked like a charm! react-hooks-global-state looks good too, I may use it too in the future. Thanks for all the help! |
@dai-shi Thanks for this repo. On RNN each screen is a seperate tree, and so you need to which has it's own Provider. Like so:
The problem is that each screen seem to have it's own context or state, how can I make sure the state is shared across screens?
Thanks!
The text was updated successfully, but these errors were encountered: