How to have global state with recat-native-navigration
See original GitHub issue@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:
Navigation.registerComponent(
'Templates',
() => props => (
<Provider>
<Templates {...props} />
</Provider>
),
() => Templates,
);
Navigation.registerComponent(
'Editor',
() => props => (
<Provider>
<Editor {...props} />
</Provider>
),
() => Editor,
);
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!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
State persistence | React Navigation
To be able to persist the navigation state, we can use the onStateChange and initialState props of the container. onStateChange - This prop...
Read more >Storing global state in react-native/react-navigation app?
I have a react native/react navigation app with two screens. Before I implemented react-navigation I had a overarching App component that ...
Read more >Using React Global State with Hooks and Context | Savas Labs
At the top of the component tree, ie in App.js, define global variables, and the Hooks to update their state. // App.js import ......
Read more >How to manage your global state in a React app? | Medium
What options do I have to manage my React app state? ... For example, React Router for web apps or React Navigation for...
Read more >Storing global state in react-native/react-navigation app?
Related Query · Sharing state across React Native app with React Navigation · React Native Android, several apps instances running at the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
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. In short, we don’t need to re-invent the context api for this.
If this is the goal, I’d encourage you to try https://github.com/dai-shi/react-hooks-global-state It will work like a charm.