447 points · by iredd · 3y ago · 547 comments
People tend to compare these frameworks on things that don't matter - often it's performance. We used to compare React performance to AngularJs performance too, which was meaningless.
VDom is nice. Reactivity in signals is nice. Limiting rerenders is nice. But I choose frameworks because of developer ergonomics.
The killer feature for React was - 1. JSX - typing and auto-complete for components, colocation. 2. No direct dom access. (Good bye $element)
Most frameworks outside react still use templates. Even when they support JSX like syntax (aka vue 2.0) the default are templates. Templates are a no go for me. I use them for blogs or static websites, but applications are easier to make and maintain with actual javascript.
Luckily none of the other frameworks, even Angular, have rampant direct dom access anymore.
Hooks aren't a problem in general. It's just the useEffect hook. Unfortunately that's a big problem. That hook should never have existed. And it was clear from the start it'll be a pain from the limitations around it. It requires a mental model detached from everything people are used to and from other things around it.
When using React I usually just use MobX and everything just works.
React is very sluggish when updating many elements at once, for not very large values of "many". With some regularity, I've debugged React+MobX jank issues where a bigger update, such as switching from one panel to another, takes upwards of 200ms on a mid- or low-range machine.
None of this is perceptible on our beefy dev boxes, which is why I think people disregard it, and why the modern webapp experience is so miserable for the average person.
1. Performance is very very rarely a contributor to a product success. Users prefer more features over more performant app all the time (both directly when asked and indirectly by what products they choose).
2. Rendering/client computation speed is rarely a contributor to real and perceived performance. It's almost always the async calls - how many you have, and how long they take. It's almost always a waste of effort to try and make your framework render at half the time when 99% of your lag is a database call.
3. Framework performance is rarely a contributor to the speed of your rendering. It's most often a problem with how you structured your app. You can structure your app poorly in any framework. (I would hazard a guess that in your panel switch example a differently structured React+MobX solution would not have the problem you described)
4. There are only very few scenarios where the rendering speed between frameworks makes a perceptible difference (usually when talking about large tables or similar scenarios), in all other cases it's a difference of a few milliseconds.
I close sites all the time when they fail to work quickly. I have aborted orders on sites midway through when the interaction became sluggish enough that I wasn't confident in the value of the product anymore.
This statement reminds me of those Gordon Ramsay shows where a restaurant owner says "the customers like my food!" when it's obviously subpar. The fact is that the customers that didn't like the food politely go away and don't come back.
Your other points get more directly at framework performance versus other performance concerns. I have fewer opinions about those.
Yet this is what all the JS people were saying in 2014 - 2015 when everything started to become SPA. They argued this is what the users want. That's been used to justify all this stuff for a very long time if you're on Twitter. When it gets traction within Twitter it leaks into orgs. It's the same argument that's used now for all the SSG,SSR,hydration,edge and whatever other buzzword.
The internet is miserable because of all these React sites. I know first hand because my wife has a Chromebook. Yet developers won't listen because they think 6x cpu slow down is good enough to test with on their $4000 Mac book pro.
If users really don't care that much about performance then why aren't we just rendering html and sending new html on every interaction. That's much easier to do, performs pretty well from a CPU/Memory standpoint.
We've taken on a lot of complexity over the years in defense of the users. The argument I go back to is what is "good enough" and the developers/product/design I've worked with don't know what this word means.
Most of my successful work has been specifically outperforming the competition in a way that makes users choose our product. Performance is an orthogonal feature that improves all other features, and even changes what your clients can do with your system, as in making new workflows viable.
2. True, it depends on the type of app. For anything that is a type of "editor" - website builder, word processor-like thing, kanban board - you operate on a data model that you save in the background. Async calls are fairly unimportant for the overall feel there.
3. To me it's hard to untangle. The reigning paradigm is declarative UI, for great reason. It's so much saner than any manual updates. But this encourages a design where you don't think about what DOM updates will really happen after an action, and this is where the problem lies. A big part of it is also the DOM model and layout. In the extreme, you have a declarative UI library like ImGui which doesn't have any VDOM, it just rerenders every frame, and it's insane how quick it does it. I haven't been able to bring it to its knees, it just maintains 60FPS constantly, with a lot of frame time to spare.
4. It's not hard for me to believe this. I didn't say other frameworks are better. Could be that the whole DOM diff approach is the culprit, or the slowness of DOM updates and relayouts.
This is absolutely true!
I would say that some frameworks make it easier to make mistakes. For example, Angular can be highly performant...but the automatic change detection kills performance. But wait, you can fix that! Just make your components use OnPush Change detection! ...which is not...the default? Why? In any Corporate app that displays complex UIs you absolutely need to be using it everywhere. but yet.
Personally, I think it is to make it easier for beginners who don't understand why their observables are not showing content on the page but it is still annoying to set it in every component or hunt it down. This is a small part of why we turned to using nx and generators with configurations that add it by default.
You might as well say, having users is very very rarely a contributor to a product success. We're over two+ decades into the 21st Century and we're still pushing a 20th Century mindset?
Why Lord? Why?
https://infrequently.org/2023/02/the-market-for-lemons/#shri...
We have a React+Redux search page where clicking checkboxes takes about that long to update the checkbox, on our good developer machines.
I won't rule out we did something wrong (this page was pretty early in our React understanding), but we've also not managed to fix it due to how much is on that page.
It was all redux’s magic and simplicity was making almost the entire thing rerender on every keystroke. Of course it was the developers fault, but it’s so easy to end in that situation that I blame the tools because to me when you shoot yourself in the foot that many times you start to ask yourself if what you have is a footgun.
I see this claim a lot and I'm curious what this is based on, can somebody drop some links to further reading?
I don’t have any numbers, just some anecdotal experience like the above.
It is not just speed. The UI of many sites suck too. Amazon, GoDaddy, for example.
Then there are ads. We don’t see ads in between content anymore. It is content within ads these days.
I am thankful that we can do so much online these days. But the experience could be better
I'm averaging a 15-30 second TTI on the most js-heavy sites.
We still get <100ms page delivery with server side rendering and lightweight JavaScript DOM overlays. Our React infested competitors, not so much to the point their clients have been shitposting on twitter about it.
And we actually can debug our product!
N.B. No one is using the app from their mobiles. iPad and computers only.
Our reasons for choosing React when there are so many alternatives: prior knowledge, ergonomics, easy onboarding, ecosystem.
90% of the users use shitty hardware. Everything is sorta sluggish on their computers - they boot up slowly, the bunch of crapware in autorun take their sweet time to load & phone home, their wifi us overburdened with devices. Most of the software experience is sluggish for them. They don't care if their web app is sluggish too.
Nngroup used to publish analyses of the state of usability, but I don’t think they have done one recently.
The old ones always showed progress, and that’s also what I would expect talking about the average situation.
Average progress doesn’t mean there are no shitty situations and we should always strive to improve, I just think claims like this are not helpful as they are used to make blanket statements about nuanced situations.
Unless you can back them up of course, and I would still love to see the data if anyone can find it.
Then i noticed a stark differences in attitude in the 2 studies I did at uni. One was more plain compsci. The other more web/mobile design and development. The later paid absolutely 0 attention to optimisation. Whether it was speed, download size or anything of the sort. The former treated an inneficient slution as invalid or at least graded lower. (Note this was in Beligum)
First time I started paying more attention to this where it wasn't when it wasn't in the context of being a budget constraint student was when I did a temporary IT support stint at a gigantic international pharma company and the software was so sluggish it was....insane. Dozens of people at our facility staring at a slugish webinterface waiting at every action and doing loads of those for every ticket. It was so infuriating I tried to make a browser plugin to prefill stuff with comon defaults the moment they were available knowing I'd never use it beyond those 3 months. Years of time must've been wasted staring at little loading circles because management did not use the software.
Then when I made native software for a manufacturing industry niche where i was told some suggested db retrieval and prerendering optimisations and such weren't worth the time....And sure. These were lowwage foreign workers using it, it didn't hamper much at all and our time was expensive. Maybe the business wouldn't get the money out of it....but then i ventured to production and notice more than a hundred people pulling the same actions many times a day thousands of times a year ....and see them waiting split seconds or multiple seconds depending on the actions that counted up to combined wasted minutes, hours, days, weeks and I realised what a load of bollocks it was.
Additionally when I helped extend various ERP's I realised the old ones were faaar from great but the move to web based interfaces really didn't do us much favours.
Then I come home and try to help my various layman family members on their comparatively slower windows and android devices and it becomes veeery apparent that this is not just a professional software issue. Slugish UI libraries on slugish frameworks on a slugish OS with various other slugish apps.
Coming home to a fast pc running Linux and using stuff i write in my free time using C++ or rust or even just various native apps on windows feels like such a extremely stark contrast.
My conclusion is that users won't care enough up to a certain point as studies show However I do believe that what those studies don't show is that for a good part this is because it's the default for many of them. They think this is just what tech is and all those countless small waittimes behind actions is normal.
Hyperbole. Web apps would not be so ubiquitous and popular for solving business problems if your claim was true.
But yeah, I guess you're not waiting in line at the bank anymore.
I've gravitated away from React towards Vue v3. Templates are working fine, well even. You still use similar amount of Javascript (probably less).
> It's just the useEffect hook. Unfortunately that's a big problem. That hook should never have existed.
Weird. useEffect is like the archetypal hook. The problem it purportedly solves was one of the main arguments they made for hooks existing in the first place -- https://reactjs.org/docs/hooks-intro.html#motivation. They just implemented it in a clunky way, and actually the problem could have been solved in an OO fashion without going to hooks at all, but now everything is a fucking hook.
There was (and still is) a real problem in react with composability. Which they tried to solve with mixins, then HOC and then hooks.
The three main hooks are useState, useContext and useEffect . useState and useContext are very straightforward and an overall improvement on their previous counterparts. useEffect was an improvement over mixins, but it was a worse solution for class component lifecycle methods.
It was fairly obvious that useEffect had a lot of problems from the get go, but it was deemed worthwhile to add so that functional programming proponents could have state without classes and to finally have a way to use composability without the horribleness of mixins and hocs (which were worse then useEffect).
The real problem is that useEffect has it's own problems, and while we no longer have the old problems, the new problems might be worse.
Performance people get offended when they hear things like that. I imagine what they will tell a person who says something like this is to:
- Look at the traces. Real metrics, on real devices that users have, not the one that developer has.
- Consider either large contentful paint (will likely be subpar with client-side rendering) or first input delay (will likely be subpar with server-side rendering). Consider, too, the new interaction-to-next-paint metric (rumoured to be bad with all js-heavy sites)
If these metrics look good, then great; carry on doing what you are doing. If they don't look so good, then, they would say, reflect on whether what you are building is losing the business money by driving users away.
For example, if you have a React-based wrapper around some SAP Gateway calls to replace the standard SAP UI then the user doesn't have much say. Because of the perceived better UX. The users of the solution inside companies (think multinationals, larger government etc) your call agent that use the React-based SAP portal can't really say I am not going to use it. Hands are tight.
The only time performance really matters when you have paying customers
I do not like JSX. It’s not worth talking about why. It’s not an argument I want to have. But framing non-JSX approaches as objectively inferior is not in tune with the reality, being that this is something sensible people disagree on.
It’s pretty hard to get more “this is my opinion rather than a statement of objective fact” than this.
> I do not like JSX. It’s not worth talking about why. It’s not an argument I want to have.
Ok.
Um… well, it’s hard to have a discussion if you won’t talk about it…
…but, “code” templates allow autocomplete and type checking in a way that is an objectively distinctive superset of text templates.
It’s because they are code.
A template is (almost always) a weakly typed DSL. Written, ignoring all the history of language design… by a bunch of folk who don’t really know how to write programming languages. …and, they. Are. Bad. Not always… but often. …because writing a language is hard, and because (reason) you can’t ever use an existing template language. Oh no. This framework has to have its own unique one, because otherwise it doesn’t integrate tightly.
Do you like DSLs? Or do they just hide the complexity somewhere else? What if the DSL is bad, not orthogonal in its feature set, poorly implemented …but cute, and useful for a very very narrow use case.
Isn’t the main critique of react that it hides complexity by moving it from one place to another?
Don’t you think it’s a tiny bit ironic that all the other templates based languages with their custom template DSLs are doing the same thing?
Anyway; I think it’s fair to evaluate template languages as what they are: DSLs.
JavaScript is a better language than most template languages by a variety of metrics. Other languages are better than JavaScript, absolutely… but, never, have I seen a template language that is.
You can love declarative configuration all you want, but it’s very very difficult to argue that just because you can make a mess with procedural approaches that they are worse; because they are a strict superset of what’s possible using the declarative approach.
…so sure. I don’t but “JSX is easier to maintain”, but it’s distinctly superior in capability.
You can argue the fact JSX better integrates syntaxes from a proper programming language makes it better than other templating languages (and I’m not going to try persuading you otherwise), but the “JSX is better than template language because it is not one” stance you’re implying won’t help you win any arguments.
I guess there are specific features you find compelling: it's typed, has good tooling for completions in your editor?
These exist in other template languages, and ones that transform more readily to HTML (which is the goal, don't forget).
Maybe you also value that it has a straight-forward, well-defined transformation to javascript?
That's OK, but since HTML is the goal, it doesn't seem right to optimize for an intermediate representation. To me it's a weakness of react that you have to work with HTML as javascript (which JSX mitigates fairly well, but is hardly ideal).
If you want to have it all, try Svelte.
JSX is objectively better than than the scores of templating systems out there. You get much more: type checking, use of JS for logic, and no need to learn yet custom arcane syntax. If anything, I think JSX is not used and supported enough.
In the general sense, JSX is just syntactic sugar for function composition. That it works well for html-style components is a side effect; it could certainly be used for more than that.
I wish languages like Typescript would support JSX natively, with absolutely to dependency on any React-like library. Let me declare a function using JSX, e.g.,
type Mode = “upper” | “lower”
const capitalize = (str: string, mode: Mode) => mode === “upper”? str.toUpperCase() : str.toLowerCase()
const join = (mode: Mode, …arr: string[]) => arr.map(str => <capitalize {{ str, mode }}/>).join()
const joined = <join mode=“lower”>Bon Jovi /> // “bonjovi”JSX is objectively better than than the scores of custom DSL templating systems out there. If anything, I think JSX is not used and supported enough.
In the most general sense, JSX is just syntactic sugar for function composition. That it works well for html components is a side effect; it could certainly be used for more than that.
I
MobX is signals library. In other words, you are already using the signals way of doing things if you mostly manage your state with MobX. I still use MobX as well if I think I can't use SolidJS.
SolidJs if you haven't looked has MobX-like tools built in, computed, autoruns and all the same tools, it triggers "renders" when one of the signals changes. In reality it doesn't have renders, because it's not based on VDOM, but it makes it look like it does.
However I like to keep my signal library separate, I would wish SolidJS had separate signals library I could use elsewhere as well.
Also SolidJS is big library and framework by now, it comes with risks if Ryan Carniato were ever to loose interest.
Edit, I also found that Ryan has created an example of MobX and JSX without React, it's a good way to demonstrate that React is not as important with signals libraries: https://github.com/ryansolid/mobx-jsx since you know MobX that example probably makes sense.
From a brief look at their website, the downsides for using SolidJs for me seem pretty big. At the very first example, if you change it slightly you can see my problems:
const CountingComponent = () => {
const [count, setCount] = createSignal(0);
const interval = setInterval(
() => setCount(count => count + 1),
1000
);
onCleanup(() => clearInterval(interval));
if (count() % 2 == 0) {
return <div>Even count value is {count()}</div>;
}
return <div>Odd count value is {count()}</div>;
};
1. MobX let's me use objects without additional syntax (createSignal, count() instrad of just count)2. The fact that the component does not rerender and that my code does not automatically change between even and odd text means I'll probably need to have an additional mental model for writing SolidJS components. Using React+MobX I just write as I would write any other function and it'll just work (There's magic involved, but manageable magic)
Performance on the end-user device, especially if you're just under/over certain thresholds like 1sec to switch "tabs" or whatever you're using, does matter. Especially if you're trying to get people to buy stuff.
I wish all developers had to routinely try their products on a low-end 2-year-old smartphone. That would take the discussion of whether performance matters to a more informed level.
Unfortunately, React went from less-capable and more understandable to more-capable and less-understandable model. But yeah, that's just a newbie-coder take.
I dislike when JSX is framed as "just Javascript". It's really not - it's a templating language, just a very odd one - like its spiritual predecessor.
Personally I find JSX to be write-only and hard to reason about when looking at someone else's code.
Same. React as a UI library is great. React as a state manager (hooks) or a framework is (hooks or hooks+next) is not good. Writing and fusing business logic to a framework is always a bad idea
I understand that sentiment, but it's part of the reason why computers today don't feel faster than in the past and why we waste sooooo incredibly much energy.
> People tend to compare these frameworks on things that don't matter - often it's performance.
Performance matters in a lot of contexts. If you’re doing complex stuff performance matters. If you’re a public facing site depending in search traffic performance matters.
I’ve ended up disliking React simply because it’s become this one size fits all solution that 90% of web development goes through without it ever being necessary. There’s nothing wrong with React itself but it’s often applied badly.
Conceptually the body of your component runs on every render. If you want to have some effect on your component not running in sync with that then you have useEffect to set it up and clean it up not when the component is mounted, unmoutend, rerendered ... just when the stuff you are interested in changes.
Could you expand on this. You assert that "applications" are easier to maintain with JS, but blogs are not?
Are you defining "application" here as something with dynamic and interactive content?
Also, why is it easier to "make and maintain"? I'm not necessarily disagreeing, just curious as to why you believe this.
For apps the majority of value is functionality and that's where a lot of changes happen.
The main problem of maintenance happens where there is the most change - in JSX programming (I.E. functionality) is a first class citizen and it lends it easier to change. With templates content is much more of a first-class citizen.
Of course this is all in the margins, you can write blogs/static sites well in react and applications well in template-based languages. The tradeoffs are just a bit skewed in favor of each, and it mostly manifests when you don't have time to be disciplined about changes.
This also happens in the backend, but the difference is that the company país the price in the form of more infrastructure. But in the frontend is “free” so why care at all, right?
Composition API: https://vuejs.org/guide/extras/composition-api-faq.html
Pinia (state management store): https://pinia.vuejs.org/
TypeScript support: https://vuejs.org/guide/typescript/composition-api.html
While I mostly stuck with JavaScript, personally I found the setup more convenient to use than working with hooks in React, and Pinia is also more like MobX than something like Redux, in that you don't have to work with too much accidental complexity for relatively simple setups. Sadly I don't have examples from that project, because it was proprietary, but the linked docs are nice.
You're a react guy, alright.
I played with Vue and svelte and now a firm React user, mainly due to its ecosystem, for most products the slowness of React does not play a major role at all for me.
or you could try the newfound craze: signals.
1) JSX - It's terrible. Svelte, Vue, Riot... they all got it right. JSX, mixing a weird syntax of HTML and JS together is just inferior to HTML with additional markup.
2) I don't know why but every react project has crazy levels of abstraction. Everything is 15 layers deep and making any sort of change requires way too much effort to navigate 15 files and code reading to make the most mundane changes. Other libraries seem to suffer from this to a far smaller scale.
<a v-on:click="doSomething">
preferable to the jsx version:
<a onClick={doSomething}>
or even this loop example from the vue docs:
<li v-for="item in items">
{{ item.message }}
</li>
better than its jsx counterpart? items.map(item => (
<li key={item.id}>{item.message}</li>
))Then, what about conditionals? Or slots? Or classNames instead of classes? The saving grace of JSX is that it allows the creation of multiple small components inside a single file.
The DOM output that Lit produces, peppered with magic comments, looks disgusting though :-(
<a @click="doSomething">Vue you can do
<button :disabled="!isFormValid">Submit</button>
In React I've seen people do: if (!props.isFormValid) {
return <button>Submit</button>;
}
return <button disabled="disabled">Submit</button>;
This is just an example, obviously you can write this better in React. My point is there's /always/ so much conditional markup like this in every react project I've come across or worked on.Edit: I donno how to format code on here sorry. (oh figured it out, bunch of spaces)
Hard disagree. Every time I work with Svelte\Vue I wish it had JSX, which is way superior to templating because:
- Creating sub components in the same file is super important. Going to a separate file, copying all the imports, writing emits, then going back and importing that file is too much hassle for a simple case where you have a carousel with cards. Refactoring is slow, components end up bloated.
- Passing down functions is more convenient than emits. For all the talk about how svelte is boilerplate free, it's equivalent of passing down a function and calling it is at least 5 extra lines of code.
- Passing down JSX elements is more convenient than slots. Every time I need to remember how to do named slots in vue\svelte I have to read documentation, while in React the mental model is obvious.
I think I reflect the entirety of the user base of the internet when I say "fuck you" (not you in particular, just the trend of shitting on performance so we have apps running like it is 70's and tape drives on our gigahertz CPUs) here.
People laugh at web development, especially the frontend, for changing libraries every week but you read a thread like this and everyone is so sure that React is a bad library and we should be using some newer library instead.
I work with React daily and it has issues, but I find most issues can be worked around without much trouble. It's easy to hire people, onboard people, and if there's an issue you can be fairly sure that someone else out there has had an issue too and there's a solution to be found.
I'm not in a hurry to replace React, but I don't need to. React is stable enough to rely on in my honest opinion.
Yes they'll know the React part. It's the Redux/Mobx/React Router/whatever snowflake libraries you chose part that will be more difficult. I really don't like incomplete solutions personally.
React + GraphQL + jotai is my preferred stack
Needing Jotai on top of React's defacto state management is the issue. TFA talks about an ecosystem of libraries that attempt to fix React's shortcomings. Pure React does have undeniable shortcomings like proper, non-brittle routing.
All of these libraries are standard and easy to approach; when I was freelancing, my onboarding on React projects was incredibly quick, and I pushed bug fixes and features within the first few hours of joining a project. React's productivity boost is often overlooked; most developers should easily understand a fairly well-written React component connected to a Redux store.
But if we don't replace it, I appreciate if React introduced fine-grained updates and changed their attitude towards performance. I think as an industry, we have been pushing the "optimization is the root of all evil" statement beyond it's limits and now all software is super slow (except maybe games and some nice things like Excalidraw).
As I'm writing this, I noticed that Excalidraw uses React, so I wonder what's their secret sauce. Maybe recoil?
(All that said, I don't blame people for choosing React for certain classes of projects, the economics of hiring new devs, the relative maturity and stability , the large community etc all make for powerful incentives to choose React)
Because what React is as a library today, with functional components+hooks is completely different from what React was when it first came out, with class components.
React is quite clearly a name that incorporates at least 2 distinct libraries which are supposed to be fully compatible but they’re not…try using a ref for a functional component.
The existence of these 2 libraries under the same name means thst documentation is also increasingly confusing. It also means that both libraries are probably making compromises So they’re still compatible with each other on the surface.
People laugh at web development, especially the frontend, for changing libraries every week
that's a 2016 meme. Things have been remarkable stable since.But other than that, yes, frontend is pretty stable now.
Frontend is still a fast moving space with a large ecosystem - and I get for some, that's not ideal. But this 'frontend fads' meme isn't really reflective of the current reality.
Webpack - 2012, Next - 2016, Nuxt - 2016, Nest - 2017, Parcel - 2018, Blazor - 2018, React Hooks - 2019, Vite - 2020, Vue 3 - 2020, ESBuild - 2020, Sveltekit - 2020
Having worked on 3 sizable React projects now (all started before I arrived), I can only conclude that beyond a toy phase -- once you have many hands working on React and *particularly* once you start managing sizable state -- there is only pain.
The most recent case resulted in spending quite a bit of time explaining to a peer why we were experiencing an unexpected side effect and redraw and explaining how `useMemo` and `useCallback` actually need to be used [0] and made me think of Stephen King's Langoliers.
It occurred to me that "React is the new IBM" [1] It has become so dominant in the market that no one can get away from it. But that also means that it can no longer innovate. Andrew Clark's twitter post *acknowledging* that signals and fine-grained reactivity would be better for performance but that the React team doesn't care pushed me over the edge of frustration.
I think that React finds itself not too far off from where IBM was at the micro-computing revolution. IBM had become too beholden to its market and too arrogant in their own success to see their own downfall.
The traffic and feedback on the second article is an indication that there are a lot of folks out there who are really, really dissatisfied with the state of React.
[0] https://chrlschn.medium.com/8eb7bb72c87
[1] https://chrlschn.medium.com/react-is-the-new-ibm-6af2f4b04e5...
Functional components and hooks were a huge innovation to class components and significantly improved the ergonomics of the library. That was only a few years ago.
The team is actively working on RSC (react server components) which will have a similarly large impact on react's capabilities.
Frameworks like remix and next will be able to leverage and build on this to create even better systems for building apps.
The whole signals blow up event is weird to me. Seems to be a loud and extremely small minority making a fuss around it.
IMO React continues to dominate over others (Vue, Svelte, Angular, Solid etc) because its just better - it embraces JS (no v-for, ng-for, non JS language) and strictly sticks to the idea that the view is a function of state.
React continues to dominate others because it meets baseline criteria for a js framework. And has corporate backing while Vue doesn't. Angular 1 was also popular because it was average js framework with google's backing before angular 2.
Implying that React remains popular for purely it's technical merit is utter nonsense. Because if react was really technically better, then no one would have migrated to Vue, solid and svelte or angular for that matter
Fair, this instance is 100% noise imo.
We're engineers - we should be able to judge when something is silly.
> React continues to dominate others because it has corporate backing while Vue doesn't. And angular was popular for the same reason before angular 2.
I have never heard anyone in the last few years say react is better because it's backed by FB. I pick it because it embraces JS (unlike Svelte), doesn't reinvent the wheel (ng-for, v-for), and has a track record of maintaining backwards compatibility (unlike Angular re Angular vs Angular 2, hey its google what else should you expect). Class components continue to work 100%. Angular is backed by google - a much bigger company than FB and its nowhere close to as successful.
> Implying that React remains popular for purely it's technical merit is pure nonsense. Because if react was really technically better, then no one would have migrates to Vue, solid and svelte or angular for that matter
Some companies like to experiment, or have very unique challenges for which they find other tools better. I avoid Angular and Svelte - both have made such odd decisions. Some people do just prefer one tool over another! There will never be any set of capable tools where 100% of people select the same one. That's the variation of life.
Per the article's comment on forms and react and the messiness that ensues, well we're engineers. We can't expect a single library to solve every problem. We should be responsible for avoiding bad patterns like throwing from state into react state. It's 100% not necessary and should be kept separate.
React is not perfect, it's bloated, but the reason it took off is that it brought something new to the table as a general and programmatic way to construct UIs. Being a child of Facebook helped it achieve dominance but considering that before React we had angular (shudder) and jquery, React's success was well earned.
React will be replaced when something actually better comes along. The current contenders seem to want to return us to the technology of the past, it didn't work then and it doesn't work now.
That said, as a low-level library it should not move fast; it should make sound design decisions while maintaining compatibility. It’s completely open to frameworks with more opinions and friendlier DX to be built on top of it.
I see this said a lot with particular regard to hooks, and to this day I just can't buy in.
For whatever problems class components have, they enforce a general layout of the component in a way that hooks don't. Reading some codebases that are all in on hooks feels like the wild west and is frankly nightmare-ish to untangle.
> it embraces JS (no v-for, ng-for, non JS language) and strictly sticks to the idea that the view is a function of state.
So does Solid No?
A junior dev isn't going to be build as fast or as clean as a more experienced dev, but a good framework promotes speed and provides guardrails to prevent mistakes.
To that end my experience with React -- same as the author's -- is that React does not have this characteristic and provides many ways to shoot yourself in the foot.
Not only can you componentise your UI code, but you can componentise your UI system meaning teams can develop independently of each other...
Usually people are not FB and people often do not have the same kind of strict development rules or enforced discipline, nor are they as many people as FB. Maybe the FB tool is not right for them.
Once you have state that needs to span your application and prop-drilling becomes too much of a drag, the misalignment between React's "pretend we're going to redraw everything" and "I'm only changing this one field in my state" causes most of the issues with React.
I'm not sure I'd ever expect a framework, React or anything else, to stop that behavior. If a child component signals to a parent that the state has changed then I would always expect that to cascade down the node tree. That could cause further updates. And more renders. That behavior is on me. If the framework decided not to cascade some updates that would be weird.
I think this highlights part of the problem with React and most other frameworks - people expect too much from them. If you're delegating all of your coding skill to the framework and expecting it to just magically work no matter what dodgy code design you throw at it then you're going to build a shitty app. You have to remember that you still have to think things through, use your skills as a dev, understand what's happening and why. That is always going to be true. You're always going to have to put the work in.
At the beginning of the article the author says they feel trapped by React because their previous, current, and next jobs are all going to be React based. That isn't true if they choose to put effort into learning other technologies and seeking roles that use them. If you work hard you find options open to you. Heck, they could move out of web and start writing completely different code that isn't even JS if they felt they wanted to. No one is being held hostage by React. You are only held hostage by your own fear of doing something hard. Feeling like you have to stick with React is a state of mind - you can change that with enough effort.
It's not that the properties shouldn't be updated it's that in React the whole subtree gets completely re-rendered, with a potentially big performance cost. Svelte just changes the relevant bit of the DOM, like a single class attribute or whatever, and leaves everything else be, this feature alone is what made me switch. In addition to baseline performance benefits certain things which are really awkward in React (e.g. animated transitions) become non-issues.
>Feeling like you have to stick with React is a state of mind - you can change that with enough effort.
I really appreciate your optimism about switching to a different framework/ etc. and I would have felt the same earlier in my career where I didn't have so many non work commitments, financial and otherwise. But to me now this reads as wishful thinking; switching track is difficult, especially when your existing skill set represents a large chunk of the demand in the marketplace. (And I say this having recently sucessfully made the switch from React to Svelte)
No doubt there are individuals with circumstances that make switching tech stack harder due to the demands on their time elsewhere, and I feel for those devs being stuck on a stack they don't enjoy (I was a PHP dev for a decade, I understand their pain). But I also think that those problems are temporary. You might be stuck on something for a few years, but in the grand plan that is your career spending even a couple of hours a week to move to something that you don't hate is worthwhile.
It'd be awesome if everyone who dislikes React could spend a month immediately learning Svelte or Solid, or Kotlin or Swift, but that's obviously not possible. All I'm saying is that if you're not doing anything to change your future then you should seriously consider if the problem is as bad as you might say it is.
Having developed with Angular and React, and dabbling with Vue, I have to say that Svelte has the best ergonomics of the lot, and the language tutorial is so approachable. I haven't had to think about performance or state to the degree that I have in other frameworks. Any workplace could easily skill up a Svelte dev from a React dev.
Because Svelte is mutable state galore. I thought we all agreed to say no thanks to that.
Tangent: the idea that "we all agreed to say no thanks to that" is kind of symptomatic of broader issues I have with web dev. i.e. that there's very little recognition that different tools have different uses and knowing when to pick which is part of the job. Working with wood you wouldn't apply the same practices and methods to building the timber frame of 2 story house as you would to making an intricately carved toy elephant. Why when working with the materials of the web, HTML/CSS/JS, do we assume there's a best and right why to do it: "you must write tests!", "avoid using z-index!", "separate content and form", "immutable state!"; these are all the right answer in some situation and not in others.
Isn't this the whole selling point of Solid's signals? If a child component receives its props from the parent as signals, and asks the parent to fetch some data and update the state, then the child won't rerender; only the bits that are consuming the signals will. Fine-grained reactivity, they call it.
Not to disagreed with you here, but there are many frameworks out there which either claiming themselves as "full-stack" or trying to be as full-stack as possible.
The developers who uses these frameworks might just expect "(delegating your code to the framework) is how it suppose to be used"(, while blaming people who write "raw" JavaScript code as "hacky").
This is a problem which will occur whenever you want to standardize the workflow as well as the knowledge base for your team. Some approach is discarded in this process and what's left in the end are often "common practices" which nobody has reason to reject. If the "common practices" is to let the framework to do it, then that will be that.
>Things get more complicated when you start using React Context and start signalling updates in a parent component. The render cascades. Maybe one component fetches some data, some component remounts, and you run your state update again, delayed by a few seconds.
This is just doing it wrong. State should change in response to user inputs. Ultimately, React is f(newState) => UI. If that function isn't pure you're gonna have a bad time. It's hard to blame anyone though. The docs suck and most of the tutorials you find get it wrong one way or another.
That said, there's kind of a reason why functional programming isn't more popular. It can be hard to grok and there can be a significant performance overhead. There's also a reason why this sort of implicit programming isn't as popular as imperative style. It's hard to predict what the implicit behavior is and footguns abound.
The bit that is g(state, userInput) => newState is the hard part. In particular managing the scope of that newState.
Oh, and sometimes you need to handle h(state, asynchronousData) => newState too.
And then comes the fact that even though your f is _pure_, it also has to be _fast_, because it's going to run every time you get a newState.
It's like you're speaking a different language to me, and I find that so weird considering we're using the exact same framework. How am I not having any of these issues?
I'm honestly at the point where I wonder if y'all are making things harder on yourself somehow, because I could see how getting obsessed with counting every single re-render and trying to overoptimize would result in the stuff you're saying while not actually impacting perf in a meaningful way.
When I do encounter a component with countless re-renders as described, it is usually painfully obvious what causes them and easy enough to fix.
I think we're going too far if we're expecting React, or any framework, to be fool-proof to the point that we can just throw "whatever" we want at them and expect it to have peak performance.
Timing-based UIs are (such as a sequence of triggered animations) can get really messy really fast. I've seen some really messy bugs in a app that had visuals and audio tied to different timers and user inputs in the app. We eventually moved all time-based animations to observables, which helped some
- https://redux.js.org/usage/side-effects-approaches#recommend...
Remove most logic from the components into sagas,thunks and selectors.
That way your components will be smaller, more testable, easier to change, easier to reason about.
Your app is the store, not the DOM.
It really makes things much simpler. The trick is to keep all the state in the store, including when things are loading, when some user interaction is happening but not yet complete, etc.
From your comment, it seems like there may be some problem if the user is interacting somehow, let's say in the middle of doing a drag and drop, and some data update comes in from a websocket, right? Well, if that's going to cause a problem for your render it's because apparently your data-updated function h needs to know if the user is doing a drag and drop. That should get put in the state when the user starts the interaction, and now h can know about it and react correctly.
Yes, it's more complicated than just have some component render based on the data you receive, but that's because it turned out that your app was more complex than you thought, it has more states you need to care about.
There's no magic wand, but this stuff works, just adds some boilerplate code but I don't mind.
Didn't have to in the past. Back with class-based components we had shouldComponentUpdate(), and lost that when components switched to pure functions.
The clue is in if everyone is missing the point but you, may be start with more introspection. :)
I will give an example of a side project I am working on. The homepage has two sub components, one when the user is logged in, one when the user is logged out.
Now, when the user logs in, the state of the homepage parent component needs to change, the state of the nav bar needs to change etc.
Your problem is in assuming newState is completely described locally which isn't always the case.
React is not that at all. Unless your UI is very simple, React is not f(newState) => UI. React isn't functional. More on that here: https://mckoder.medium.com/why-react-is-not-functional-b1ed1...
The complicated bit is the handling of events and changing the state. Hence why you get Redux for state but there is no “Redux for views”
It's not wrong, it gives you one kind of separation of concerns: components. But "the view is a function of state" is completely misleading IMO.
> But then they added hooks and useState and useEffect and so on, which made the functions impure. The problem with hooks is that they “hook into” React state and lifecycle features, which means it is modifying global state.
React components don’t update the dom every time they run, they update the fiber tree / virtual DOM.
Only in the commit phase is the DOM updated and side-effects are run.
My rough understanding is that:
Hooks, excepting useEffect, all run in the render phase.
UseState hooks store data in the component in the fiber tree, and capture a sequential list of updates when you call setState.
Algebraic effects can seem a bit odd at first, but it’s really like a generalised try/catch. Instead of storing state in the function itself, you reach out up the stack to the component and store it there. And every hook you call from your hook stores it there too.
It’s why call order is important, because it’s how they know which is which.
You don’t modify any global state though.
The actual component function needs to be able to be called multiple times in the render phase (which just updates the vdom), and must have the same output each time, if the inputs/props are the same.
Every now and then, the tender phase can be interrupted to run the commit phase, which synchronously brakes a snapshot of the vdom and applies all the needed updates to the outside world.
Perhaps it’s better to think of as
render: f(props) -> descriptionOfUI commit: apply(descriptionOfUI)
I would absolutely say components and hooks are functional, with algebraic effects. And that the resulting data struct from those components, is what’s used to produce side effects.
Even useEffect, is a description of a side effect to run, it doesn’t run in your hook, it runs on commit with all the other side effects.
There’s a ton of optimisations under the hood but that’s roughly my understanding of how it works.
In functional programming, functions are not allowed to do that. The only thing a function is allowed to do is return a value.
> ...you reach out up the stack to the component and store it there.
FP functions are not allowed to do that. In FP functions can only rely on the parameters passed to it (it cannot refer to anything outside) and it should not do anything beyond return a value.
> It’s why call order is important, because it’s how they know which is which
In FP, functions can be called in any order (unless one function needs the return value of another), and the final result is not affected by the order.
> You don’t modify any global state though.
If you have state it is not FP, whether it is global or not.
useEffect is a side effect and if you use it you're gonna have a bad time.
Right.. but then you can't really use React for building serious UI.
function handleChange(e){
getAutoSuggestions()
setLoadingState(true)
}^ Side effects happen in response to user input
function getAutoSuggestionsCallback(resp){
setSuggestions(resp)
setLoadingState(false)
}^ No side effects
Absolutely not only to user inputs, but any kind of event: response, websockets, push notification, worker task finished... a million things beyond the basic "click".
> If that function isn't pure you're gonna have a bad time.
Hooks let you deal with "component lifecycles" which make that function not pure. Only the most basic toy react components are pure, everything is about side effects IN your views.
React had some obvious red flags; it seemed unwise to re-render entire components each time and regenerate the DOM instead of trying to work with it; it's a hack. It's not difficult to think of scenarios were it fails; for example think of what happens to an element's scroll bar after it has been re-rendered from scratch; it resets... Yet people kept coming up with workaround after workaround to all these kinds of issues. If they had tried PolymerJS (which was going for a native Web Components approach and interfaced nicely with the DOM instead of bypassing it), they would have questioned React's merits. When the useEffects hook was introduced in React, to me, that was a vindication of Polymer's stance (which it had figured out years earlier) that you couldn't completely pretend that DOM elements don't exist, yet React's solution was not as elegant as Polymer's as it was tacked on as an afterthought rather than as a carefully thought out design decision.
Nowadays, with native Web Components (HTMLElement) in most browsers, I don't see why people would still start projects with React, especially given the massive number of dependencies it typically introduces and how often they keep changing stuff and breaking compatibility.
They promised a simple component library which would be the answer to our prayers. What we got instead is a 7 year religious pilgrimage which involved a million developers simultaneously trying to make sense of it; attempting to discover its true form by inventing abstraction upon abstraction and growing increasingly fanatical as it devolved into a wicked monstrosity which should have brought the wiser among us to our knees, begging for JQuery.
I’ve always thought React was some sort of mass hysteria as well.
To this day I can immediately tell that an app was made using React once the first focus/selection bug rears its ugly head.
We can agree that state management is complex, no matter how it’s done. If you disagree, cool go build a database.
Of all the complexities around state management, the one squarely placed at the top for me is: time.
State is a variable you care about, that will change over time.
Signals and Hooks/Effects present two very different approaches to the problem.
They both require updating your mental model, and they both have specialised tooling.
Myself, I’ve never fully grokked observables/signals—particularly in relation to a UI. They shift complexity into a location that I think makes them harder to reason about.
I did take to the React approach with Components and hooks. And in my experience so did many others.
I disagree with the article saying all frameworks must have signals, and I appreciate the React core team holding their ground on that.
It’s healthy for the ecosystem to have frameworks built on different ideas, otherwise why build a new framework?
But React, if you added signals I think you would warp it’s entire foundational paradigm.
You don't want to rerender? Use useEffect with an empty array! Or don't use any state variables!
You want to show something new to your customers / users without rerendering? Well sorry, that's impossible, regardless of any framework you use and you should go back to UI development 101.
Bottom line: if you write clean code and are aware exactly of what your local state / redux variables are (or whatever state management you are using), you should never have a problem with too many rerenders. I've been writing React for 6+ years now and have NEVER had to reach for useMemo or useCallback.
When you say “render” are you referring to what React means by “render”, that it will go through the whole virtual DOM cycle? Because it most certainly is possible to avoid that when using pure JavaScript. Why do you say it’s impossible? React’s fundamental problem with performance, and the whole reason people often don’t want to re-render is because React renders everything, then does a big diff on the DOM to compare it to what was rendered before, and then updates the elements that changed. I know a lot of work has been put into making that process fast, but it’s still really expensive compared to the pure JS way of doing it. In CS terminology, updating a button or any other single element went from an O(1) operation with JavaScript to an O(N) operation with React.
My point is that updating the state for a single element causes React to compute the state for the whole page, and diff the whole page virtual DOM against the whole page actual DOM, before pushing the update of that single element into the DOM. With pure JavaScript, you can skip all that and directly update a single element. This is often in practice much faster.
But this problem existed before hooks: old school React devs will remember the days of class-based components with humongous componentDidUpdate methods peppered with calls to this.setState(...) that did the same thing.
My own impression is that hooks offer better lifecycle controls overall, with the side effect (heh..) of handing devs an arsenal of footguns that will inevitably go off if they don't fully understand the hooks or where to use them or how React detects and triggers a re-render. So in a way I agree with the author of the original article here, but in the sense that React devs should probably not use hooks until they understand how re-renders happen and why to avoid that and only then should they be handed one footgun at a time.
Compare that with Vue composition api, and you can see how idea of hooks can be implemented much better[0]
[0] https://vuejs.org/guide/extras/composition-api-faq.html#comp...
Wha- how?! The moment a useEffect depends on a callback, it needs to be memoized!
The quickest obstacle you’ll run into as someone new to React will be something like this
function MyComponent() {
const [num, setNumber] = useState(42);
// infinite loop
setNumber(n => n + 1);
return <div>{num}</div>
}Trying to make state updates at the top level of a component will result in an infinite loop.
```
I've taught React to dozens of people without ever seeing someone try this. A render function is an idempotent function that produces UI for a given state, and it's called every time the state changes. What are you, semantically, trying to do by updating state midway through a render function? This isn't a footgun, this is the author picking up a screwdriver and going "I wonder what happens if I press it against my eyeball"
I like how you say "others might not be so diligent to have read the docs"... As opposed to? Picking up a UI framework and just winging your way through LSP autocompletions until something happens on your screen?
Yes, that, and following bad tutorials by other people who did the same.
I... isn't it? Isn't this like the first thing in the hooks introductory material? If you don't find this, yeah, hooks are gonna be a bad time.
> Line 9: When the user clicks, we call setCount with a new value. React will then re-render the Example component, passing the new count value to it.
https://reactjs.org/docs/hooks-state.html
I think they assume you'll figure out that it must do so to function at all.
For the longest time React was kind of in denial to a large degree about what they were. They called themselves a View library. Hooks have definitely noticeably changed that relationship, & how people integrate app state with React, but the problem here of updating hasn't really changed all that much.
It's not a new thing either. A lot of the initial resistance to React & the VDOM was that it felt like unnecessary work. Because so many frameworks at the time were working towards two-way data-binding systems, which aren't necessarily but were often associated with with smaller, precise DOM updates. HP/LG's WebOS's underlying Enyo project was one high profile would be effort here.
Signals have definitely been a good re-grouping point, for reconsidering what the shape of things might look like, for trying to do a better job.
I'm a bit surprised we're still operating so much at a library level regarding reactive systems/signals. JavaScript objects have quite a lot of flexibility already, and the addition of Proxies added a lot of capabilities. Faint/distanct memory, but I think Proxies were justification for killing Object.observe[1]: now users could do whatever they wanted, so we no longer needed a JS native way to see objects change. Yet, we're still very library based, rather than trying to make objects themselves better, more reactable.
[1] http://web.archive.org/web/20200218195131/https://developer....
React has no real answer to state going sideways.
Then there is controlled/uncontrolled component which is an example of structural instability (what looks like a tiny change to your boss is a bigger deal than it should be) unless you ride the crazy train and use “plain ordinary javascript” to build a parallel system to move (some of) the state around.
To test the context itself: pass as children of the context components to render the context state.
To test the components within the context: create a context with mock functions/values.
React has no answer to state going sideways because React manages a tree of components, and you are not supposed to connect random branches of a tree. That would completely break the concept of tree, container/contained, and just convert everything into a graph, and graphs are much harder to deal with. BTW, HTML is a tree, not a graph.
Controlled vs uncontrolled and the boss demanding a tiny change is just another case of bosses not knowing about how it works the system and imagining things and then demanding reality to conform to their imagination. Not an issue with React.
Instead, it feels like most state management libraries ultimately end of writing their own Chrome extensions. Which now that I say that makes me curious: do any of these executions also let you observe/monitor server-side state management systems?
The problem each of them tried to solve, and continue to try to solve is purely lexical in the end. It's about writing things differently. Creating abstractions (terms) beyond what the underlying language/platform allows you to do.
And this is not a bad thing. The solution really is to create your own language so you can express the problem you are solving in the terms of the problem and not the underlying language/platform/hardware.
And then I sigh again... aah but if only Common Lisp and it's macros were the underlying platform.
That's what Elm is about. I've talked about it in another thread, so I won't repeat myself here.
DSLs also usually are an incomplete solution. Unless they themselves allow adhoc language creation using the DSL as a base. Common Lisp with its macros allows writing DSLs quite off-handedly as you program. You grow your program and language together as you get deeper into your problem.
Being able to use such similar concepts/knowledge for both web and mobile, with strong results in both places, that’s something React is uniquely good at (AFAIK), and a huge reason to choose it IMO.
[0]: https://quasar.dev/
Checked, yeah. Using Cordova or Capacitor. They say it looks native, though? No idea.
> What I like about React/React Native is that it’s web-native components on the web, mobile-native components on mobile, so you get true native look/feel/behaviour in both places.
Oh, that is cool. I never worked with anything mobile, so I didn’t know. I will read into that, not that I plan to use it, but it sounds interesting :D
But React/React Native is the only mature/popular web/mobile approach I’ve seen that embraces web components on the web AND mobile components on mobile, which I think is a big advantage. Though maybe there are others I’m unaware of!
I’m sure there could be React Native like solutions for other libs/frameworks, but I haven’t seen any that are as mature with the same “native components under the hood” approach.
But hey, if you are under 10 people and need apps everywhere, it is a nice thing.
- Dedicated Android devs working on your Java/Kotlin/whatever Android app
- Dedicated iOS devs working on your Swift/Objective-C/whatever iOS app
- Dedicated web devs working on your JS/TS/whatever web app
- Dedicated BE devs working on your BE services, in 1-many languages that may be none of the above
But for startups, that’s not gonna happen, there’s gonna be wayyyy fewer devs and wayyyy less specialization. A lot of companies will be in that mode for many years, possibly indefinitely. In those situations, React Native can be a big win. I’ve been working the past 2 years at a relatively small startup, ~10 devs, that’s TypeScript everywhere. We’ve got 2 mobile apps (mobility space, a Rider and Driver app), both TypeScript/React Native/MobX. Rider is iOS/Android/web, Driver iOS/Android, very nice having 2 apps instead of 5. Then a web-only admin app in TS/React/MobX, and backend services in TS/Express. Same language everywhere, and similar mental model across all FEs, is a big productivity boon at our size.
There are not many examples of such code bases. Maybe numerical algebra libraries come close.
Reading through the comments it seems that providing (fairly basic by now) UI functionality on cross-platform basis has not matured to the point of providing a stable paradigm.
Given how many people and for how long have been banging on this problem it feels a bit strange.
Surely people can find better use for their time and energy than churning through half-baked frameworks?
One has to ride (and eventually) create trends to sell.
We should have all stayed on backbone or Prototype.js with that logic.
People look for alternatives because the status quo is awful (slow, verbose, footgunful).
You’re saying “who needs cars when we got horses? Cars break down all the time”
The UI problem is not new. People were already building clunky UI cars long ago. MFC was introduced by Microsoft in 1992.
Of course the emergence of the web platform and mobile/touch devices complicates the matter as you now have a proliferation of platforms to address (desktop native, desktop web, mobile native, mobile web) but my argument is that fundamental patterns on how to do this efficiently should have emerged by now - and I see exactly the opposite.
It would be nice to see some sort of convergence. Reinventing the wheel might be "fun" or gainful in a narrow sense but it certainly doesn't help with productivity.
I don't understand this quote from Tanner. Aren't React hooks, like, the only way to tell a function React component (while inside of it) to re-render? And if you look at the code of, say, the useBaseQuery hook of tanstack-query, you will indeed find React's native hooks being used there [0].
0 - https://github.com/TanStack/query/blob/main/packages/react-q...
While of course React-query plugs into the React lifecycle, it's also kind of an escape hatch that plays nice with React.
Managing the fetch function calls, their state, their resolutions, and the cache, all probably happens outside of React, but then changes to any of the query state are reflected into the React lifecycle.
This probably lets him do something like using localstorage for storing cached query data, communicating between tabs, etc
At the end of the day, they approach the problem from two different directions, solve issues in two different ways, and end up with two different sets of challenges in terms of what's easy and what's hard in them.
I've definitely written React UIs that would be easier in Angular. But I've also crashed Angular performance through the floor trying to wire up a table display with Angular update hooks. Angular makes it easier to hide state-update dependencies in a way that causes really bad thrashing to reach steady state, which I've (anecdotally, generally) found harder to do in React because doing it in React involves writing a lot more code and a lot more cross-state dependencies.
Most of the footguns listed in this article are things you obviously shouldn't want to do because they're not React-y.
E.g. if you are dealing with forms a lot, I would strongly suggest using react-hook-form or formik.
It's a pretty major rant, without putting forward an alternative.
The only viable alternative for me personally is VueJS and that's not my cup of tea either.
I like React. It makes sense mostly.
Is React perfect? No.
Do I like React's recent transition to focus server side? No.
But the problems it addresses are tough to solve.
Show me a better solution and convince me its tangibly better than React.
I think React creates needless complexity. The software I write is complex by it's nature, I do not need the software I create my application within to exponentially increase that complexity. React does not just let one write code and create one's application, React dictates how the code is written, and if that does not fit with one's application structure you must change it. And React developers cannot wrap their heads around anything other than React's dictated way to write React, so... they are useless.
So, what do I use: nothing. I just write html/css with direct DOM access via js, very minimally. Dicking around with the web page is the least priority of the applications I write, and the freedom to create the application structure as the purpose of the application dictates is far more important to my clients. Plus, I do not write consumer click bait vehicle software, I write software for people to accomplish things, typically complex things of the nature an engineer, designer, or architect would use.
I've gotten to the point where I think frontend code should just be modeled as state machines from the start. I like XState but you can use reducers too if you like.
Back with components, it was trivial to compare old and new values and change the state based on that.
It reminds me of teachers who have been teaching so long that they don't understand what it's like to be new to the subject any more. It's called The Curse of Knowledge cognitive bias: https://en.wikipedia.org/wiki/Curse_of_knowledge
No affiliation, happy user for years.
I would recommend you to build a small project, maybe a Todo app in every framework you want to try, or maybe if you have a project, build a small part of it in each (I will pick the part that you think is the trickiest to build with React or the framework you are actually using).
Also I'll recommend to also check Qwik and Fresh(deno).
Not a single one of the many projects I’ve worked on in the last 10 years needed such a level of interactivity that it justified the trade offs of using react or any other frontend-heavy frameworks.
I’ve seen entire CRUD spas that would have been built in 20% the time if we didn’t have to build a graphql api, figure outs authentication and permissions, integrate that with a custom validation setup, integrate all of the above with the translations systems, coordinate deploys or do forward compatible migrations, etc, etc. so much energy (and money) wasted.
But I'm also interested in trying Solid.js and Vue, and for some types of projects I'd likely even go Astro+Svelte or Astro+React.
Hard to speak authoritatively on the matter though because over my career I've only done vanilla JS, jQuery, Backbone.js, React, and then Svelte, in that order, and each has felt like a leap forward in evolution
I only advice against using a niche framework if you suspect the project is gonna be long-lived and managed by a medium to a large team, in that case pick the one of the big ones—React, Angular, Vue, or Svelte—which your teammates can agree with.
I despise what NPM has become, and how complex / time consuming the build pipeline of front end apps is.
It’s still not a mature framework yet but hot damn does it excel at just getting out of my way and letting me ship stuff.
- Lit if I wanted to share components with other teams
- Marko if the site had lots of static content
- Qwik if speed was paramount
- Fresh too looks interesting
I'm glad others have found value in the evolution of react, but it always felt like watching a tragedy from the outside as the newest Abramov idea seeped through the ecosystem.
My own impression is that the core model of state and rerendering is actually quite nice and intuitive, though often explained a bit wrong. The part that makes it complex and confusing are things like callbacks, which can trigger lots of unnecessary rerendering and force quite some boilerplate if you want to avoid that. If you can remove all the stuff around trying to avoid rerendering unnecessarily, React would be a lot simpler.
I also think that people are too quick to use the wrong tools for managing state in React, e.g. Context to avoid a bit of prop drilling.
React enables v=f(s) by making DOM updates faster. v=f(s) was always a good idea, but before vDOM, replacing the HTML of the page on every little state change was too much for the browser.
- Now you describe your views as pure functions of their inputs and stop caring about them, React cares about them. You know that with the right s, the right v will follow.
- You need to care and manage your app's state carefully, yes, and everything goes in there. Fortunately, patterns and frameworks like Redux make it releatively straightforward to do this.
You can still make a mess, sure, and make mistakes, etc, of course. No silver bullet. But you can now deal with those two separately. If you start fetching data from your components directly you're back in jQuery hell with extra steps.
I may be wrong here, or it could be my age showing, but I feel like explicit UI systems like that might be more verbose, but I find them more accessible to dive into and less "magic".
I'm totally lost and baffled by everyone's enthusiasm for these increasingly arcane and complex abstractions. I suppose they are necessities that arise when you reach a scale that I have not yet encountered (I work on small to medium sized teams of a dozen or dozens rather than hundreds of programmers).
Alas, castles and fortresses have been built with messy goop, and the amount of goop-specific tools and goop slappers far outweigh the bricklayers. So I too slap goop.
I mean, they're absolutely necessary because the goop is full of insects. But so elegant!
I've been running a mobx-react setup for 7 years. It's been thru a few syntaxes but it behaves identically. Minimal rendering, observability, I find it the most intuitive state management pattern.
my forever setup is here:
I have also been able to consistently hire absolute greenhorns right out of tech bootcamps with zero formal computer science training and they were able to build features that made our company real money and push to production within the first two weeks. React can't be that bad.
Now that we threw out react-hook-forms (Remix does it all fine with default form APIs), Apollo (don't need their caching any more, so just sending plain GQL requests via fetch does the job), Redux (Context API is just fine), emotion (TailwindCSS is so so so so so much better)... our Remix codebase is basically pure HTML and Tailwind's css classes. It's a bliss.
> Humans have a cognitive bias: "what is focal is presumed causal".
> Political leaders know this. They like presenting good news themselves because they like to be "seen" as causal of good stuff, but they'll get a press secretary to deliver bad news. Movie directors know how to use this when framing their protagonists within the story.
> Unfortunately, the React team have lost themselves in this bias. They keep trying to make the most focal part of the system (components) also be the causal part. Please stop doing that! It is a mistake. Events are what's causal - they embody the user's intent.
> Just to be clear, I love React. What an utterly brilliant idea and great execution. I'm deeply grateful because, wow!, did it change things. It is just that I preferred React when it was only trying to be the V part of MVC. Everything since has been downhill.
[0]: https://day8.github.io/re-frame/FAQs/LoadOnMount/#why-this-d...
This line however "It is not obvious that your component re-renders on state updates." is kinda strange, maybe it's not obvious if you didn't read any documentation or tutorial?
also "You could build your own framework in an hour using reactive primitives [...]" is the same as when people say "just make your own sorting algoritm", yeah sure you can get the exact behaviour you want, but come on.
It's an additional layer on top of MobX that adds strong typing. I've been using it for an open source video annotation project and it's been amazing for keeping track of local state, cascading calculations of things.
Here's my "models" directory for it if you want a taste of how it works:
https://github.com/Rodeoclash/vodon-player/blob/main/player/...
Upgrading to newer versions is a pain and also finding well supported third party libraries. React is much easier to work with since you don't always need to reinvent the wheel for time consuming things.
Hooks and simple state management with Jotai are also much nicer to work with than RxJs. RxJs requires a strange mental model and a lot of verbose code and functions.
Angular is kinda like Java, more code for less features. Great if you don't wanna think, meh if you want something exciting and new.
Does immer count? :)
struct A { b : B }
impl Reducer<Action> for A {} impl Reducer<Action> for B {}
Now the reducer logic is spread out across the state. Sure, every sub-state now need to handle Action every time but with tools like ADT and pattern matching I don't think its as bad. I feel like this will be cumbersome, but the complexity should scale linearly.
(Submitted title was "React is a fractal of bad design")
I started out in these sort of frameworks doing Angular 1 in 2013. Did a lot more Angular 1 projects in those years, and really got to know the intricacies of the framework. Was ready to switch to Angular 2, but instead I ended up doing some native JS web components, a little React, then some Vue, and now some serious React.
I've got to say, I liked the little React a lot more than the serious React. All those useEffects everywhere don't make the code any more readable. There's layers upon layers upon layers of components and abstractions and layers in between. It comes across as less organised than my old Angular 1 or Vue code did, though that's probably also due to the size of the code.
Anyway, I'm not being held hostage by anyone. Next project I hope to be doing something in Svelte, but maybe I'll end up doing something completely different. Maybe some Kotlin? I still haven't used that.
On the other hand, other less experienced developers didn't like Elm so much because React allows you to write your app with fewer lines of code. The article from this discussion explains well that React (especially with hooks) hides complexity, which bites people later. At that time, it is perhaps too late to switch to something else.
Needless to say, I haven't been able to convince any other employer to use Elm, and then I see issues popping out all the time that would never happen with it. Such a waste, just because people like shiny toys and just follow what others around them are doing without thinking too much.
[1] https://elm-lang.org/ [2] https://redux.js.org/understanding/history-and-design/prior-...
For example, I recently wrote a react component that diffs it's new state against the previous state and then calls an imperative map API to bring it into alignment. Ideal, no. But I'm not going to wait for the compiler devs to do something perfect before I write this app.
But I think the criticism here is a bit sharper and more pointed than that. The author isn’t expecting Reach to do something for which it was never intended, I think. Instead, they’re saying that the abstractions (hooks in particular) that have evolved over time expose unhelpful interfaces that either conceals too much information, encourage poor patterns that lead to bugs, inefficiencies, etc.
In other words, the criticism isn’t of React’s explicit decision to offload responsibility outside the scope of outputting UI, but rather that it’s evolved to make handling of those responsibilities more challenging.
I think that’s a bit more serious than the former critics and worth at least considering. For my part, I’ve found little substantive advantage to hooks and do think they hide a lot of bugs by making implicit things that should probably be (and, once upon a time, were) more explicit.
Having to write optimized code usually makes dev ergonomics the first casualty.
Like the famous Haskell qsort. Every beginner sees a cute version that should never see the light of a production environment
Most of this article is a rant against the react hooks project, not React itself.
1. I’m not sure what they have in common with each other. What exactly is a React hook. Nearly every hook is its own thing, with its own purpose, use, etc. With the new “use” hook, even the original hooks rules don’t apply anymore.
2. Related to the above, every hook is an entirely new concept. Learning react you would think once you learn “hooks” you will be able to understand basically what they did. Much like once I learn “classes” or “functions” I can figure out what they are. But every hook is its own concept, with its own rules, and gotchas, etc. Sometimes I wonder if the reason they’re called hooks is to present them as a single Concept, otherwise it would be too obvious that React replaced a few concepts, state, and component lifecycle, with about 3-5 concepts in the library in the early versions, and many more now, with an infinite possibility of concepts through custom hooks.
3. No one in the React world seems to have a clear mental model of what hooks are. useEffect is the most egregious here, but the name (and the original React docs) indicated it was for side-effects. But then it’s also used for lifecycle management. Finally, it appears that now the React devs have started pushing the idea that it’s to keep “components in sync with an external system”. And useEffect is probably the most used hook outside useState.
To be fair, usually descriptions of concepts can change with time. But with useEffect it’s not just the description that’s changing. It’s the entire mental model, which makes it seem that the React devs themselves are not clear what useEffect is supposed to be.
Fundamentally, hooks seem to be a bunch of ad-hoc solutions that React devs use to solve specific problems they notice in the wild. But there doesn’t appear to be any fundamental consistency to what they really are.
The first example of UI frameworks is always the `counter`, but it's always the least realistic scenario you encounter. Almost every app involves retrieving state over the network, sharing state in multiple places in the app, and how this state is CRUDed.
The reality is that all state is very interconnected.
Ideally you want fine-grained reactivity for every rendered UI element, that ultimately reacts to the changes in a database in the cloud.
And every piece of state should ideally be persisted. Even things like dropdown menus and their state.
The simple solution to all this is to store all state/data in a single database on the client. Every time you render something from the database, a component should have its own "view model". And this view model should react to changes in the database.
This "view model" also shouldn't be hidden inside components. There should be one place where you can view all the view models throughout your code. And see the interconnectedness. In a visual way too.
Maybe we went off-track when we started to merge the view/model/controller in the same file. We create hierachies of views, and then they need to get their data from this view hierarhcy. But instead they should be getting their data from a central database in as few transformations as possible.
The mistake people make is trying to make components isolated and decoupled from the rest of the app as a principle. It sounds nice, in that when you work on a single component, you only have to worry about what props are being passed to it. What makes apps complex though is data transformations. Ideally you want data to be as close in shape to the underlying dataset as possible. Otherwise caching/memoizing becomes very difficult, and this is usually the cause of many performance issues.
I wonder how many of the issues people have with React are due to it not being built on a state management library - like Vue is, and Mercury was.
The rendering is whatever. Templates, JSX, it doesn't really matter. Mercury used hyperscript and we got by just fine. But state management is critical, and React seems to leave it completely up to you.
Vue added a hooks-like API. While I haven't used it in anger, I've toyed with it. And it sidesteps some of the weird React hooks caveats... because of Vue's reactivity system. Huh.
*With a brief interlude using the original Angular, which I did not understand then and still do not understand looking back from today.
> It’s just abstractly funny to watch the ecosystem of a UI renderer work so tirelessly to keep using it while avoiding every part of it.
I would call this concept noodle. Because when there's a lot of them you get back your tasty spaghetti. The whole reason for React was avoiding it whenever possible.
I use sometimes, but for the most part is overused feature.
I think thats a symptom of a problem with the front end community, people get too attached to the new thing and try to make it the standard instead of building something stable and concise.
Im tired to having to rewrite a code because one library that I had to upgrade decided to migrate to the "new thing"
And using it professionally for years now, there's still some cases I can't wrap my head around. And the mental model is just a bit "off". Like, the same function is ran multiple times, but with different behavior (like a useState only uses the parameter the first time the function is ran) which is very unclean.
I’d love to know who started using it first, though.
It's not even orange for me. I changed the "topcolor" in my profile settings to d0c8b5 - a darker shade of the body background color. Now the only orange thing is the Y logo. Much easier on my eyes this way.
Why the modern obsession with hiding the underlying state machine with callbacks? To prevent devs from seeing the bigger picture?
I'm lucky that I am an independent developer so I can choose to use Solid JS in my projects.
React has so many gotchas and they keep changing the 'best practices' I can't believe people still stick with it.
Does anyone have a source?
In game dev you run millions or even billions of computations 60 times a second. If running toTitleCase three times every key stroke is an example of a compounding performance problem in React then surely the problem must lie deeper.
POST/Redirect is beautiful. It’s fast. It’s simple. It’s low maintenance.
> What would framework-integrated fine-grained reactivity look like? Probably something like Solid.js
It would look like JavaFX which has had this exact approach since it launched over 10 years ago as well as a large library of observable operators and collections complete with delta events, the ability to define components with a "shadow DOM", with custom CSS properties, using both JSX-like widget-oriented markup and code, and a whole heap of other things the web community has since slowly rediscovered. Here's the high level observable operators API (there is a lower level one that lets you define custom operators):
https://openjfx.io/javadoc/19/javafx.base/javafx/beans/bindi...
And here's the author's Solid.js example in Kotlin with FX:
class Counter : Label() {
private val count = SimpleIntegerProperty(0)
init {
textProperty().bind(concat("Counter: ", count))
timer(period = 1000L) { runLater { count.value++ } }
}
}
You could also write that in many other languages like Clojure (with cljfx for FP fans), Python, Ruby, JavaScript, and of course Java. It would be less verbose if I used a library that better used Kotlin's features, but the goal here is that you can look up the APIs from the link above (there are a couple of implied static imports).So not much different, but it demonstrates how the text property of the label is bound to a dynamically computed string which is in turn bound to an observable number. When the timer fires, the count increases and the label is recomputed. Everything is done that way so layout computations, for example, won't run unless the size of the label changes. And that's it - no need for VDOMs or prop drilling or state memoization or any of these other performance hacks.
At some point you'll observe that this seems a lot like "reactive programming" as used on the server side, and then might want to explore a library like ReactFX which connects these two worlds together.
https://github.com/TomasMikula/ReactFX
There are some other nice features in this type of toolkit that the web community seems to be heading towards. I'd be willing to bet a lot that at some point they'll even reinvent inheritance under a new name, because being able to write code that's generic over component trees is really pretty useful. The hooks/functions model totally wrecks that and has led to this explosion of "design systems" (otherwise known as themes that bundle half a widget toolkit), none of which interoperate properly or can be coded against in an abstracted manner.
None of this is to say that FX is perfect or that React/SolidJS etc are the wrong tools to use. You can run FX apps in a browser using a form of server side rendering - check out https://www.jpro.one to see a fully crawlable website that's actually implemented using JavaFX on the server with no frontend/backend split existing at all. But it only works well if you don't have a fast and reliable server connection, plus a server with plenty of RAM and CPU. Alas browsers pull all sorts of mean tricks to keep people locked inside the HTML5 sandbox so JS frameworks aren't going anywhere, but it would be nice if that community spread its wings a bit and looked at prior art from outside their language. GUIs are old and the challenges involved in them aren't new, and from the outside it looks suspiciously like there is no real progress being made here, only wheel spinning.
we are all just primates staring at blinking lights and poking things
I need a web server to work by slapping together fifteen Java libraries from thirteen different code houses and writing an absolute Shoggoth of shim code to convert between their types and classes? Sure, whatever, datacenter storage is damn near free.
I need to put code on a client machine on the internet? You'd best pick one of these date libraries, because there's no way in hell we're justifying shipping moment and Joda down the wire.
It seems like the framework culture is driven by the search for a silver bullet that makes problems go away. But each solution to a problem always comes with its own set of problems, only these problems are initially unknown. So you trade a set of known problems for a set of unknown ones.
It is possible that these new problems are lesser problems, but this is hard to verify upfront, and the nature of being unknown makes it a lot harder to deal with them preemptively.
So anyway, you have your framework, you have used it for a while, and you have learned about the previously unknown problems that it causes. You could rejoice that you now have this knowledge, and therefore have a reasonable shot at working around the problems. But instead you ditch your imperfect framework and search for a new one, beginning the cycle anew.