Hacker News new | ask | show | jobs
by zer00eyz 853 days ago
I mean it's a stake in the ground for a conversation.

React is bad at "static" content. What happens when large portions of your site are cachable and a small but important part is highly dynamic (SPA like). Building that monster in react is a pain in the ass. You end up running a node server, and all the fun that comes with that, just to give a consistent developer experience to your js/front end/ full stack team.

If you go back 10 years the HN community would happily shit all over PHP for its sins. Yet node/react seem to get a pass. I dont see any one screaming about the fact that JSX is the same as PHP mixed in HTML. (and im going to get down voted for that).

React isnt bad, but the web is not a SPA, a lot of it doesn't need to be a SPA. Articles like this are pushing the js community to a reflection point. One in which it can embrace the lessons of the past that it missed and move forward in a better way. NO, isnt the answer... better tools and tooling is.

1 comments

> React is bad at "static" content

Of course, it's a view library meant for dynamic content, that's the whole point of React. That then people who learned React and try to build other things with it, isn't the fault of React.

If it is such a pain in the ass, why not use an alternative that is less pain in the ass? No one is forced to use React, and if you have a bunch of developers that use React/JSX just because, maybe it's time to have a sit down and talk about alternatives.

> I dont see any one screaming about the fact that JSX is the same as PHP mixed in HTML

Because it's arguably not the same. JSX is syntatic sugar for "functions as views" using built-in JS types. Creating an element is `React.createElement('h1', {}, 'foobar')`, so it's actual JS.

What people did (including myself) back in the day of PHP development was having templates as individual files on disk, parse them as strings and then try to "make them come alive", that paradigm is very different from templates-with-JS.

If anything, what we did with PHP before is much more similar to what VueJS is doing today, with actual "templates", than code-as-views that React/JSX offers.

> but the web is not a SPA, a lot of it doesn't need to be a SPA

Agree, developers tend to learn something and then try to shoehorn it into everything, even when they actually needed a screwdriver instead of a hammer. I'm probably guilty of the same sometimes too, but mostly just for fun and giggles.

But you're right that many of the things we see today as SPAs, don't really have to be SPAs at all in the first place.

> That then people who learned React and try to build other things with it, isn't the fault of React.

The discussions always get muddy here. React, the view library, can't directly be blamed for how people use it, its just a collection of code.

The react codebase does include quite a few features that support using it for more than just basic view rendering of dynamic content though. Hooks support async logic that really doesn't belong in the view layer, context providers get muddy quickly as they can pass around more than serializable state, and with server components react is arguably not even a view library at all.

The problem is ultimately how devs chose to use, and how to promote the use of, react. Given that the codebase also supports those use cases today though, its reasonable to me that people often peg blame on react itself.

>>> If it is such a pain in the ass, why not use an alternative that is less pain in the ass...

If I were building a mostly static site, I can reach for htmx, if I am building a spa (b2b back end) I can grab react.

What happens when you're building something that does BOTH. The tooling isnt really there to support this. You end up with something that isnt good at either and 4 times harder to work with... It feels like we have gone backwards at that point.

> If I were building a mostly static site, I can reach for htmx, if I am building a spa (b2b back end) I can grab react.

https://htmx.org/attributes/hx-boost/