Working with global state management issues
React is designed around the concept of components. In the component model, everything is expected to be reusable. Global state is something that exists outside of components. It's often true that we should avoid using a global state where possible because it requires an extra dependency on a component. However, a global state is sometimes very handy and allows us to be more productive. For some app requirements, global state fits well.
There are two challenges when designing a global state:
- The first challenge is how to read a global state.
Global state tends to have multiple values. It's often the case that a component using a global state doesn't need all the values in it. If a component re-renders when a global state is changed but the changed values are not relevant to the component, it's an extra re-render. Extra re-renders are not desirable, and global state libraries should provide a solution...