How To Handle UI State In Redux/React - Redux-UI?
Solution 1:
Our team has spent some days on this. The reasons we want UI states, instead of putting those states to Redux's state tree, can be:
Those UI states are only relevant to a very small number of components. But yet sometimes we need to share those states amongst them. For example, a Button to control a Modal, they both need to read/write the 'isModalOpen' state.
Those states are not data, they are UI preference and it is fine to reset them to the default upon component unmount. Persisting them in the single Redux store sounds like polluting the state tree.
We tried:
- Creating a separate redux state tree just for UI.
- Add a main branch, say 'state.UI' for all 'UI' states.
However, all these involve having to use/implement custom middleware, actions and reducers. Hard.
At the end, I made react-provide-state. It works really well. The only drawback of it is your can not easily see the ui states like states in Redux tree in browser console. And you can only update states through UI (user action event callbacks). That's fair, it is UI states we are talking about.
Post a Comment for "How To Handle UI State In Redux/React - Redux-UI?"