Live data from Hacker News

Things I wish I knew about state management when I started writing React apps

medium.com

131–140 of 335 posts

Re: Things I wish I knew about state management when I started writing React apps

#131
post #79

Earlier quoted context omitted.

For reference, here is a "simple" app - a parametric EQ designer that supports doing pink noise measurements of speakers (or headphones if you have the right equipment) with FFT in the browser: https://eq.spion.dev/ - works as an entirely static website :) Typically what people say is "oh most websites won't need THAT" but the appetite for interactivity only grows with most companies, so you could easily end up in a…

What definition of static website are you using here? If I turn of JavaScript all i get is "You need to enable JavaScript to run this app."

My definition of static website has always been the it doesn't communicate with a back-end.

Re: Things I wish I knew about state management when I started writing React apps

#132
post #31

To manage state in our React application, we have a "service layer", just like you’d see in a server side application, only these are based on state machines (reactive services based on RxJS observables works as well). We also created associated custom hooks that allow developers to easily "inject" a service into their React component (we use React's Context API for our "DI container"). From there developers can read…

I wouldn't call it the "best part." It sounds like you took the service focused angular patterns you were using before and shoehorned them into a React application.

How comfortable would you be allowing an outside dev to hack on your codebase without a _long_ conversation beforehand explaining the idiosyncrasies?

Re: Things I wish I knew about state management when I started writing React apps

#133

I'm one of those "old dogs" who don't quite get the advantage of using React in the majority of the cases it's used. This article didn't really help... > What makes these frontends complex? State management. The frontend “knows” a lot of things, and these things interact with each other in non-trivial ways [...] Example: dark mode support. For example, say your app has a dark mode. All your rendered components must k…

Yep. In my last dark theme effort. It's mainly CSS work.

Re: Things I wish I knew about state management when I started writing React apps

#134
post #84

Earlier quoted context omitted.

I actually write a good bit of React professionally. I'm familiar. I just have yet to see a very compelling case. And the excuse is almost always this nebulous "rich/complex interaction". And.... I just rarely see any good examples of this. The huge majority of apps (web or otherwise) are not video games. They're forms that submit stuff to a server and get a response. There's sometimes a dropdown here or there.... an…

Mmm, I work on a multimedia sequencer (timeline, viewport, etc) in the browser, it would be utter hell if the whole thing was put together via manual DOM updates in something like a Backbone View render function. I know this because when I joined the company, they were trying to do it in Backbone. For a project of that scope, this was a great way to introduce a large surface for error and maintenance (the project kic…

> when React was launching and Typescript wasn't public

Minor correction, React came out about 7 months after Typescript. That said, Typescript had a promising birth but a rough infancy, so I wouldn't blame anyone for considering it released only after 1.x versions starting in late 2014.

Re: Things I wish I knew about state management when I started writing React apps

#135
post #26

Earlier quoted context omitted.

You got that wrong. Modern JavaScript / SPAs make it possible to implement something like Outlook right within your browser. No (big) download, no clicking through an installation wizard, no fragmentation of versions for a tool, which forces you to be online anyway. I don't get all the hate towards SPAs and JavaScript Frameworks here on HN. Everyone is basically complaining about complexity for applications, which ar…

I find lots of these "requirements" come from developers that are bored with their job and need to spice things up.

Are you implying realtime notifications on a chat or email service is not a requirement?

Re: Things I wish I knew about state management when I started writing React apps

#136

Earlier quoted context omitted.

I've worked on a few applications with 'rich/complex interactions' and everyone on the team was opposed to using any sort of JS framework. That was nice because it was relatively easy for anyone to trace through the application as needed. In my experience if the application state is overly complex then that is a result of the design, and that usually leads to a bad experience for the user.

In my experience if the application state is overly complex then that is a result of the design, and that usually leads to a bad experience for the user. Though it is possible to overengineer this, you're probably underestimating ho seemingly simple apps can justifiably have complex state. Say you make API calls. Your application state just grew to reflect 1. Pending request 2. Request succesful or failed 3. Request…

Oh I agree with that, I just think that the internal state of the app can be more easily managed if those potential application states are explicitly identified during the design stage.

Re: Things I wish I knew about state management when I started writing React apps

#137
post #75

Earlier quoted context omitted.

> unit test anything but the individual pieces Isn't that the definition of a unit test?

Debatable but I get your point. The thing is that Flux is a pattern, and you often want to test the full pattern to get a meaningful "unit" of behavior/logic. There can be meaningful logic in the individual pieces, but frequently they only make sense as a whole.

It's not debatable...

Unit tests are for testing individual components of your application (web or otherwise)

e2e or integration tests are for testing your application component/lib/api/whatever boundaries

Re: Things I wish I knew about state management when I started writing React apps

#138
post #82

Ok, only tangentially related. I would appreciate anyone more knowledgeable than me in React chipping in: Why Redux is the norm for React state management? Follow-up specific question: In which cases is it better than react-easy-state[0]? I am using react-easy-state on my company and on my side-project web apps. For me at least, it seems to add much less cognitive overhead than Redux. It is simpler to understand, sim…

I'm a Redux maintainer. There's a bunch of reasons why Redux took off: - In 2014, a year after introducing React, Facebook announced the "Flux Architecture" concept [0]. Since it was mostly just a pattern and not a library, over the next year the community created dozens of competing Flux-style libraries, which I've referred to as "The Flux Wars" [1]. - Redux came out in the middle of 2015. Its design took inspiratio…

Can you comment on why people who like Redux on React don’t use it much when moving over to Flutter?

I’ve heard “yea, you can use Redux, but don’t” a lot.

Re: Things I wish I knew about state management when I started writing React apps

#140

> but you do need to figure out how to store global state that can be accessed anywhere in your application. Immediately I disagree and feel antagonistic towards this article. Then the author provides an example of "prop drilling". Sounds an awful lot like Inversion of Control [1]. I've been down this road before. Next comes a Services pattern [2] (the world re-invents COM once again) and then comes Dependency Inject…

No, none of this has anything to do with dependency injection or AOP
Post reply on HN