I'm making a really simple application with react native and redux. I'm wondering, how I should manage the state, especially for navigation. I know this is a highly opinion-based question, but I believe this to be critical for my understanding of redux. The navigation structure is like this:
app
/ | \
role1View login role2View
/ \
formView logView
/ \
formPage1 formPage2
Things to consider in navigation:
So the question is, should I store in redux or local state
UPDATE, EXTRA QUESTION:
There's a need to add up-navigation (arrow in top left corner) from formPage2 to formPage1. Android toolbar is defined on a higher level (app), and up button visibility is stored to redux. How/where should I handle up button click?
I think this response from Mr. Redux himself, still applies as best practice here: https://github.com/reactjs/redux/issues/1287#issuecomment-175351978
Use React for ephemeral state that doesn't matter to the app globally and doesn't mutate in complex ways. For example, a toggle in some UI element, a form input state. Use Redux for state that matters globally or is mutated in complex ways. For example, cached users, or a post draft.
So generally, if the state is relevant only to one parent component and one or two levels down from there, it is probably best kept local. If the state can be touched by siblings of that parent component or others that are higher up or elsewhere in the app, it's likely a good candidate for Redux.
Relating this back to your app, I think you already have the right ideas. Especially when views are fine losing their state upon navigation, there's really no point keeping that state in a global store.
Routes tend to be a global concern, which is why react-router-redux is quite popular, to keep route state in the redux store. However, since your tabs are not supposed to be accessible globally (unless this might change in the future?), it's still cleaner to keep that route state locally, I'd say.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.