Live data from Hacker News

Just Fucking Use React

justfuckingusereact.com

31–40 of 48 posts

Re: Just Fucking Use React

#31

Earlier quoted context omitted.

The react's algorithm of detecting changes is based on rebuilding a Virtual DOM tree (i.e. recalculating all components) and comparing that tree to the previous one. It is done, as I understand, every time someone calls update() or similar method on a component. So React won't cause performance issues only if you have few model variables or manually optimize the code by using immutable data structures (which have the…

That comparison is apples to oranges, because React components are typically much smaller than Vue components (think 20 components in one file). So while its true that a state update will rebuild an entire component, that diff might still only impact 2-3 dom nodes. For high frequency updates such as reacting to mouse interactions, you can compose components in such a way that only one small component handles the high…

> So while its true that a state update will rebuild an entire component

What if the component does some long computations, for example, calculating a sum of 10000 elements of an array? React will do the computation only to find that nothing changed.

Re: Just Fucking Use React

#32
Some time ago I myself was in camp of people who preferred minimal web as opposed to all these "bloated" frameworks. But one thing that changed me is Tailwind, it improves the complicated stupid old way I wrote CSS classes so much that all people who keep hating it just because it's one of those "bloated" things of modern webdev are just ridiculous.

Then I tried React, quite liked it but preference for something as small and fast as possible lead me to Preact. And as I have no need for hosting websites with backend (I just want client-side interactivity so static pages) I found how to do prerender workflow where all necessary html is generated at build time and interactivity gets hydrated on top of that by bundled js module. It's so much better than trying to figure out pure js interactions in site made with static generator with some obscure templating.

Though for some reason people nowadays mainly focus on running site as SSR through Node rather than just hosting static pages and figuring out static build workflow in those frameworks can be very challenging.

Re: Just Fucking Use React

#33

Earlier quoted context omitted.

That comparison is apples to oranges, because React components are typically much smaller than Vue components (think 20 components in one file). So while its true that a state update will rebuild an entire component, that diff might still only impact 2-3 dom nodes. For high frequency updates such as reacting to mouse interactions, you can compose components in such a way that only one small component handles the high…

> So while its true that a state update will rebuild an entire component What if the component does some long computations, for example, calculating a sum of 10000 elements of an array? React will do the computation only to find that nothing changed.

Put that computation in a useMemo and you're good.

Re: Just Fucking Use React

#34
post #22

Earlier quoted context omitted.

This is the virtual DOM mental model of react, and it is pretty much entirely wrong. - React doesn't really distinguish between DOM components and your own components in how it evaluates. It's all part of the same "VDOM" tree. Creating and updating HTML tags doesn't flow differently from updating the props on your own components. - React does sparse updates, starting at the topmost component(s) whose state changed. F…

> If a component is memoized with `memo(...)`, then a re-render will be stopped if it has the same props as before This works only with immutable data structures. Am I wrong? Because a modified array will pass the identity test (=== operator). If you are using mutable data structures, you cannot use identity operator to detect changes. Also if "memo" optimization is that good why does one have to add it manually? > I…

Yes, immutability is a requirement. And if you think that's a "special style of coding" then you probably haven't run into situations where that is a necessity, like optimistic updates with rollback, or undo/redo systems.

Mutable code is code that destroys the paper trail of what happened.

>The point of UI framework is to do the optimization for me

No, the point of the UI framework is to allow you to build applications that work correctly and perform well. The React style of coding is designed to scale up to large applications of e.g. a Figma or Excel caliber, while eliminating entire categories of subtle bugs. If you've never coded something like that, React will seem like it is getting in your way.

>Also if "memo" optimization is that good why does one have to add it manually?

Because the compute vs memory trade-off isn't always free, especially in a world where CPU computations are much faster than accessing uncached memory.

Re: Just Fucking Use React

#38

Earlier quoted context omitted.

That comparison is apples to oranges, because React components are typically much smaller than Vue components (think 20 components in one file). So while its true that a state update will rebuild an entire component, that diff might still only impact 2-3 dom nodes. For high frequency updates such as reacting to mouse interactions, you can compose components in such a way that only one small component handles the high…

> So while its true that a state update will rebuild an entire component What if the component does some long computations, for example, calculating a sum of 10000 elements of an array? React will do the computation only to find that nothing changed.

This example just sounds like it was coded poorly. I would assume that experienced React developers would know to avoid something like this.

For inexperienced developers, you don’t need a framework to do something dumb.

Re: Just Fucking Use React

#39

"sometimes, complexity is not a choice, it's a fucking requirement." Complexity is never a requirement, and almost always self-inflicted.

This just means that complex projects exists. Complexity refers to the domain or business problem that needs to be solved and software complexity is a consequence of that. If you can anticipate a certain level of complexity by various factors, then you are better off with React/Vue/Whatever.js that makes your life easier.

Re: Just Fucking Use React

#40
post #27
post #12

Earlier quoted context omitted.

The article says "use React (or Vue, or Svelte, or Angular if you're a masochist - the point is a modern framework"

> modern framework Modern usually doesn't last long.

Dunno. React has been around for 12 years, Angular’s current incarnation for 8 (older than React if you count <1.5), and Vue for 10.
Post reply on HN