Consider redux alternatives (or not)
See original GitHub issueWe originally went with Redux due to it’s ubiquity, however it is certainly a bit cumbersome, although redux-toolkit helps a lot.
Here are some of the issues (please add):
- Doesn’t handle async natively very cleanly (requires thunks)
- The store is global, and when to use component state vs the store is not always clear-cut
- It has it’s own code-feel/style that feels slightly alien to react (maybe that’s more my opinion)
- Difficult to learn
Possibilities
Keep redux
- This would avoid refactoring time (though perhaps now would be a good time anyway)
- Any new volunteers are more likely to have used redux than any other form of state management
mobx-state-tree
- It deals with async much better
- It keeps redux benefits like time-travel
- Much cleaner/less-boilerplate
- It is also somewhat difficult to learn, with the added drawback that far fewer people will have already used it compared to redux
- It also has the same problem 2 as redux.
useReducers
- AFAIK this is basically redux, but scoped. Not so sure about this.
- Would probably introduce more boilerplate than redux-toolkit
- This is the only option I am personally against
Recoil
- I want to add this one in, I experimented a little with it a while ago and I think it addresses all the above issues.
- It’s really easy to learn, and while all the state does technically live globally, it’s totally opaque so seems scoped. Switching from local state to recoil state is (nearly) as simple as
useState
->useRecoilState
- It feels very react-y
- However, it requires using experimental version of react and some of the api is subject to change. Personally I have no problem with this - version pinning would still work and facebook is using it in production.
- We would get other benefits from the experimental react features such as
useTransition
if we wanted - No one anywhere has much experience with this and there is presumably less resources on how to use it (stackexchange questions, etc.)
useContext
- 100% scoped state, pretty easy to use
- Lose some features such as time travel and easy persistence
- Has a bigger potential for performance issues than other options
Issue Analytics
- State:
- Created 3 years ago
- Comments:29 (29 by maintainers)
Top Results From Across the Web
You Don't Need Redux — 3 Simple Alternatives for State ...
Alternative #1: React Contexts ... The simplest alternative to Redux is to use React's built in Contexts functionality. One of the many important ......
Read more >Redux Alternatives in 2021
Redux Alternatives in 2021 · #1: Just use React · #2: Just use React + SWR || React-Query · #3: Redux Toolkit ·...
Read more >Top 4 Redux Alternatives With Comparison Table - eduCBA
List of Redux Alternatives · 1. MobX · 2. GraphQL · 4. Helpers/generators with conventional redux.js.
Read more >MobX: a Redux alternative you should consider - Hanno
When it comes to managing app state in React, people usually default to Redux. I'll explain why we chose Mobx instead, and why...
Read more >5 Alternatives to React Redux in 2020 - Bits and Pieces
We looked at a few of the most commonly used alternatives for Redux that work independently or can interact with redux in React...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, everything is fetched with IDs and is referred to by id. Which was annoying before, but looks like it could end up being a benefit.
I guess we resolved this now with React Query with the final refactor @lucaslcode did 🎉