How to Handle UI State in Redux/React - Redux-UI?

微笑、不失礼 提交于 2019-12-09 02:16:26

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:

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

  2. 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:

  1. Creating a separate redux state tree just for UI.
  2. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!