Hacker News new | ask | show | jobs
by bayesian_horse 1798 days ago
React only gives you tools to reduce your problems.

In the case of single page apps, preventing you from shooting yourself in the foot is outside its scope.

What you are describing sounds more like a general problem in state management, and you'll have that with any framework. A common way to avoid such things in React applications is with Redux.

Unfortunately, even those advanced tools need to be learned and applied.

1 comments

As used in practice, React has you replace one set of tools with another set of tools. React likes to "own" parts of the DOM tree and crashes or otherwise misbehaves if anything else touches them -- and the way people generally adopt React is by making it "own" larger and larger portions of the page until it "owns" everything on the page. (Or by writing the app so that React "owns" the whole DOM tree from the start.)

And when you use it that way, the way that everyone who has ever used React uses React, it can indeed cause problems of its own! Half the time, the only reason people build single-page apps is because they've destroyed their page-load performance by using heavy JavaScript frameworks! If you make a big nested component hierarchy, and then it turns out you need a component to affect something nine levels below it in the component hierarchy, and you have to modify all the intervening components or rig up a Context provider or something, that is a problem that has been caused by React's design! If you put a piece of state in Redux, and then it turns out you need to access it in a place that does not have easy access to the Redux store object, that is a problem that has been caused by Redux's design!

You can say "ah they just haven't learned to use the tools properly", but then we're back to noticing that anyone capable of using React to write good code doesn't need to use React to write good code.

I've used react for years now and never had those problems. I've used components managed by other libraries and React didn't crash.

There are tons of ways to access state in a redux store elegantly from anywhere in a javascript application. Yes, if you think that is the difficult part, you are clearly doing it wrong...

And please don't write single page applications when you don't know why you need one... There are plenty of reasons why SPAs can provide a better user experience. If you do it right.