by davedx · 4y ago · 0 comments
Author's opinion, and one I find very strange. JSX with TypeScript is one of the best features of React, it's a dream compared to Angular's awkward arcane syntax (that didn't have type checking until what, a year or two ago?).
I get that people don't like React, that's fine. But "React is popular because it's popular" is an intellectually dishonest argument. There are obviously good reasons technically competent people choose it for projects.
It might actually be popular because it's popular; that isn't necessarily a dishonest argument on it's own. But usually when something is popular because it's popular it's also technically competent to enough of a degree that it's good enough.
It's disingenuous to say that React got popular for no reason and now people just don't want to change. React-isms ooze all over everything that came after it. If it was just "meh, good enough" until something better came out, then why does Preact name itself after React and have a react-compat mode and base itself on JSX? If React was just "meh, good enough" then why does every other framework out there take inspiration from React and when React came out with something all these other frameworks came out with their implementation of that feature?
I'm currently doing Angular again and I hate it (especially combined with NgRx, why do I need half a dozen observables, reducers, actions, selectors, etc just to make a HTTP request?), it's a step back from React in my last assignment; React's functional style with hooks and react-query was a great combo.
I'm not saying it's the best, but it worked for me. For my next trick, I should learn Vue.
Although on the other hand, front-end fatigue kicked in years ago. It's just the same thing again; some forms, validation, layout/style and a REST API, just using the tool-du-jour. Sigh.
I distinctly remember when React came out, pretty much every framework out there had to pivot to incorporate at least one of the 2 major ideas React brought with it (or at least, these were the most immediately beneficial features at a time when IE was still officially supported). The virtual DOM and one way data binding.
One way data binding didn’t even exist as an option in any other web framework and it was such a breath of fresh air. In fact, competing frameworks used to strongly advertise the fact that they had 2 way binding and how awesome it was. And 2 way binding looked great in your toy TodoMVC app, but absolutely failed when developing applications for real world use.
And the virtual DOM was so much faster when it first came out.
That's helped a ton with the frontend fatigue for me. All the benefits of a SPA without writing any JS.
So far I've not gotten to use that stack professionally, but I'd sure love to.
I should have said "software engineering experience" instead of "professional experience".
I'm not impugning the author, but it does provide context as to why he may not understand React's design choices.
Somehow people think there's a lot of foresight and wisdom in JSX invention. There's just so many good properties JSX has. But JSX was merely an easiest solution to an immediate problem.
Think about how React was created:
1. DOM management complexity gets out of hand. You solve it by treating view as a function of state (great idea btw).
2. If you do it naively, it is going to be slow. You make it performant with VirtualDOM.
3. Now that you went with VDOM, writing HTML is a nightmare. You address it with JSX.
JSX is obviously a great replacement for manually written render functions. But you know what's even better? Not writing render functions at all.
Same with setState() vs MobX/VueJS approaches. setState() was (is?) a horrible way to manage state. But it was the easiest thing that allowed you to implement V = F(S) formula at the time.
setState() a cost, not a benefit. JSX is a cost, not a benefit. I wish people stopped praising it.
JSX is easy to dismiss as a "hack to solve problems", but there was more thought put into it than is immediately obvious. It's no less a template language than other template language. It has trade-offs and advantages. At least it's not pretending to not be a template language like Angular's pretends to "just be HTML" even though it is very much not just HTML (and is closer to ColdFusion, to be unjust).
Facebook was using React in 2011, TypeScript was released in 2012 (and it's not like it was immediately adopted).
Even the predecessor tech I mentioned E4X, which were the XML extensions to ECMAScript 4, the "lost" JavaScript version, were built on static typing. The most controversial feature that killed ES4 was static type hints. ES4 never directly showed up in browser support, but it did impact web development as ActionScript inside Flash and ES4 had influence on Typescript's syntax. (In some fun ways JSX with Typescript is almost a "Revenge of ES4". It's a lot better than what ES4 would have been, but it's so heavily influenced by ES4 there's a family resemblance and clues that language design is always more evolutionary than revolutionary.)
(Not to mention that the functional programming languages like OCaml and Haskell which inspired the "MVU" patterns are all about strong static typing.)
React was not built with JSX in mind. React was built with JavaScript in mind. JSX was simply syntactic sugar. In fact, JSX was entirely optional at the beginning and all the initial React documentation had examples with and without JSX.
https://web.archive.org/web/20131118055243/http://facebook.g...
The key point is that JSX being syntactical sugar on top of a system designed to return JavaScript is what makes it work so well with Typescript and Flow. The key insight here was that components should be described using JS and not HTML. JSX was invented as syntactic sugar to make this more palatable for scores of web devs who had only used HTML. It is this decision to settle on JS vs HTML that directly led to JSX fitting in so nicely with Flow and TS since those are designed with JS in mind.
JSX has tradeoffs, but is way better for DX and for writing stable code. I've also worked with handlebars etc, Angular (significantly) and various other back-end cludgey templating languages. Nothing is as good as JSX.
To dismiss my experiences as "Stockholm Syndrome" is mildly insulting.
I don't care about the grimy details of its origin story, I care that it helps me ship good products.
Now, the community doesn't know about that. So when you tell them that there's a better way to deal with component state, they immediately get defensive: "No, setState() is way better, there's no magic, it's very explicit".
But setState() was a necessary evil, not a genius invention. They made it super-explicit because it was the only way they could do it. Not because of some great foresight.
Is it bad? Probably not. I bet it's tolerable. But why settle for less when there are better alternatives?
Proxies have been around for at least a decade (here’s a 2010 talk about it
)
React hooks have been around for less than half the time as that.
Proxies for setState would be a terrible idea in React for the simple reason that non state variables also exist in React functional components and have dramatically different behavior than state variables. Proxies would make them both look basically the same after initialization which would lead to a ton of bugs as devs lost track of which variable was a state variable and which one wasn’t.
Technically you can use Vue as a library to add interactivity. It works ok, but you'll switch to compilation eventually.
Still in my opinion Vue strikes good balance between getting shit done and developer experience.
Svelte would be my next bet, I just don't have enough experience with it to recommend it.