Live data from Hacker News

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

news.ycombinator.com

21–30 of 47 posts

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

#21
Mobx is my go to. It's fast, and a much easier mental model to integrate. Just inject the store you want into your components

@inject

and you can call/set @observables easily.

It's much easier to onboard people. Redux is just a spaghetti mess of files upon files, trying to find the actual implementation of something. A mess.

---

I also looked into Apollo and it's obscenely good! Terrific dev UX. I'm heavily researching it currently.

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

#22

Using redux v4 with react-redux v5 for a large and complicated project. Was looking into react-redux v6 but it looks like there may be a significant performance hit ( https://github.com/reduxjs/react-redux/issues/1164 ) so will hold off on it now. react-apollo is very interesting to me, but my understanding is that we'd need a graphql compatible backend, which we don't have

> Using redux v4 with react-redux v5 for a large and complicated project. Was looking into react-redux v6 but...

This statement reminds me of my enterprise Java days. It consisted entirely of just gluing together an endless conglomeration of shit with Spring sitting at the center.

There was never actually any software development, just configuring an ever evolving mess of frameworks to talk to each other. When you offload all your engineering to frameworks, most of the bugs end up being due to some poorly understood interaction between components.

Kinda feels like the JavaScript world is starting to invent J2EE...

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

#23

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…

[deleted]

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

#24

Using redux v4 with react-redux v5 for a large and complicated project. Was looking into react-redux v6 but it looks like there may be a significant performance hit ( https://github.com/reduxjs/react-redux/issues/1164 ) so will hold off on it now. react-apollo is very interesting to me, but my understanding is that we'd need a graphql compatible backend, which we don't have

Hi, I'm a Redux maintainer.

I wouldn't call it a _significant_ performance hit. There's a measurable difference in our artificial stress tests benchmarks, and some users have reported slowdowns in specific scenarios (especially when large forms are connected to Redux).

I recently posted a roadmap issue with our plans for addressing the perf issues, and moving towards the ability to ship a hooks-based API for React-Redux:

https://github.com/reduxjs/react-redux/issues/1177

I've specifically spent the last week experimenting with reworking the internals of `connect` to come up with an alternative implementation that relies on direct store subscriptions again, and as of a couple days ago, I seem to have come up with something that is actually _faster_ than both v6 _and_ v5 in our benchmarks:

https://github.com/reduxjs/react-redux/issues/1177#issuecomm...

Still needs more investigating and testing, but this approach looks very promising.

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

#25
post #22

Using redux v4 with react-redux v5 for a large and complicated project. Was looking into react-redux v6 but it looks like there may be a significant performance hit ( https://github.com/reduxjs/react-redux/issues/1164 ) so will hold off on it now. react-apollo is very interesting to me, but my understanding is that we'd need a graphql compatible backend, which we don't have

> Using redux v4 with react-redux v5 for a large and complicated project. Was looking into react-redux v6 but... This statement reminds me of my enterprise Java days. It consisted entirely of just gluing together an endless conglomeration of shit with Spring sitting at the center. There was never actually any software development, just configuring an ever evolving mess of frameworks to talk to each other. When you of…

I'm not sure why you feel this relates to Redux, tbh.

The Redux core is tiny and very stable. There were a couple technically "breaking" changes within the first couple months after it hit 1.0 in July 2015, and it stayed on 3.x until the middle of last year. The bump to 4.x was primarily due to updated TypeScript typings.

React-Redux has also been very stable, especially in terms of public API. We've reworked the internals a couple times to address various aspects of interacting with React, but the public API has been basically unchanged since the start of 2016.

I wrote a post on "The History and Implementation of React-Redux" that explains what React-Redux does, how it's evolved over time, and why the various changes were made:

https://blog.isquaredsoftware.com/2018/11/react-redux-histor...

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

#26
I'm a Redux maintainer. I'd specifically encourage folks to take a look at our new Redux Starter Kit package [0]. It includes several utilities that add good opinionated defaults around the small Redux core to simplify common use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state without writing any action creators or action types by hand.

Long-term, I want this to be the standard way that most people use Redux.

[0] https://redux-starter-kit.js.org

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

#29

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…

Try mobx-state-tree. It's basically MobX with Redux-like tree structure written by the guy who did MobX. It combines best of both worlds. We use it at work and it's just such pleasure to work with, highly recommend

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

#30
At my current job we use Redux, though I wouldn't choose it myself (it had been adopted already when I joined). I think Redux is best suited to very large and complex applications, with very disciplined and skilled engineering teams, who talk to each other, refactor code, and have the time to think through things like the correct arrangement of application state, providing reusable selectors. Those teams, of course, would probably also do fine without Redux.

If you have a team that writes spaghetti code, or never has time to refactor, or doesn't have effective communication then things will be worse with Redux, because it makes the code much harder to follow (good luck stepping through things in a debugger to see how they work, for example).

This is mostly intended as a criticism of people/teams who think adopting Redux will solve problems with the messiness of their code. But I also think Redux is overly complicated and too abstract for 95% of projects. And don't get me started on Sagas...

I would recommend setState as far as you can push it, then choosing something conceptually simple like MobX (Or MobX State Tree), React Easy State, or whatever the one from Formidable Labs is. Using Redux correctly is not as simple as it seems on the surface, and it requires real thought and real understanding o t

Post reply on HN