Live data from Hacker News

Ask HN: How do you manage state in your React application?

news.ycombinator.com

1–10 of 47 posts

Re: Ask HN: How do you manage state in your React application?

#3
apollo has a local state link (https://www.apollographql.com/docs/react/essentials/local-st...) but I did not find it useful.

Redux is fine but I guess with the new hooks functionality one can combine usereducer and contexts to create a much simpler state manager.

Re: Ask HN: How do you manage state in your React application?

#4
We use Redux at work for larger projects, React setState/Context for smaller ones, and I'm personally a huge fan of mobx-state-tree which I think is the best solution, and can be plugged into Redux if needed.

I think Redux should not be used for everything (there are libraries like Redux-Form which I think are an anti-pattern as ephemeral state like that should never go through the root reducer on every key change)

Re: Ask HN: How do you manage state in your React application?

#8
In the past I used Redux extensively - and I have only good things to say about Redux. I recently started using React Context and found I was much more productive, to the extent that I went back and ripped out Redux code. The new hooks thing with useContext makes using context even easier.

Learning Redux, especially the "single source of truth" thing was very helpful, but my code is now simpler, easier to understand and faster to write.

I would recommend checking out React context and hooks. I would also recommend watching the Redux videos by Dan Abramov, even if you don't use Redux.

Re: Ask HN: How do you manage state in your React application?

#9
there are a lot of options out there and this thread kind of surprised me was expecting more interesting submissions. you might want to look at the original flux:

https://github.com/facebook/flux

from facebook if you app has a lot of global state needs multiple stores can be handy.

Mobx is great too:

https://github.com/mobxjs/mobx

With the current project I am working on we actually just vanilla javascript with singeltons with subscriptions (note: I did not write this, but I think it is rxjs).

anyways someone should come along with some answers.

Redux is still the easiest and with Sagas is really cool. One start up I interviewed with was using something similar to hooks, but do not remember the name of it.

Also datomic (used by om.next in clojurescript) has some really clever optimizations and is a joy to use.

Re: Ask HN: How do you manage state in your React application?

#10
Been using MobX for about three years and I think it is wonderful. Incredibly easy to use (mark your variable as observable, modify it like you would any normal variable, and any components which use those variables in their rendering and are marked as observers automatically update), very performant out of the box (only components affected by a change re-render so no shouldComponentUpdate needed) and some excellent features like computed variables for derived values which automatically update. I really urge everyone to try it out. There is the odd time when the abstraction us a bit leaky (e.g. working with arrays is a bit different to plain JS) but with proxies in MobX 5 this is much improved.

I started out with Redux and I do think it’s worth learning - not just because it’s so widespread, but the concepts behind it are worth knowing and have influenced the way I design some stuff, but I found it really verbose and slow to work with compared to MobX (and more error prone) - there probably are libraries that help with this.

React Hooks look interesting for more simple use cases but I expect I’ll stick with MobX for the foreseeable future.

Post reply on HN