State management - alexanderteplov/computer-science GitHub Wiki
- React specific ways
- state object for class component
- setState hook for functional component
- context
- context with useReducer hook
- React compatible way
- stateless
- Redux
- Apollo
- MobX
- other libraries (Recoil, Akita, etc)
Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.
Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.
My personal summary is that new context is ready to be used for low-frequency unlikely updates (like locale/theme). It's also good to use it in the same way as the old context was used. I.e. for static values and then propagate updates through subscriptions. It's not ready to be used as a replacement for all Flux-like state propagation. --- Sebastian Markbage