question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider redux alternatives (or not)

See original GitHub issue

We 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):

  1. Doesn’t handle async natively very cleanly (requires thunks)
  2. The store is global, and when to use component state vs the store is not always clear-cut
  3. It has it’s own code-feel/style that feels slightly alien to react (maybe that’s more my opinion)
  4. 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:closed
  • Created 3 years ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
lucaslcodecommented, Dec 15, 2020

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.

0reactions
darrenvongcommented, Jan 16, 2021

I guess we resolved this now with React Query with the final refactor @lucaslcode did 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found