Live data from Hacker News

Just Fucking Use React

justfuckingusereact.com

21–30 of 48 posts

Re: Just Fucking Use React

#21

Earlier quoted context omitted.

> Unlike React it doesn't recalculate everything on every mouse move event. Where did you ever get the idea react does this?

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…

> The react's algorithm of detecting changes is based on rebuilding a Virtual DOM tree

Not exactly. This is the "mental model" but not how the algorithm works internally. There are a lot of optimizations to do as little work as possible while "appearing" to rerender everything.

This is not to say one is better than the other - each has its own benefits. But that's not a reason to choose Vue over React.

Re: Just Fucking Use React

#22

Earlier quoted context omitted.

> Unlike React it doesn't recalculate everything on every mouse move event. Where did you ever get the idea react does this?

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…

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. Frequently this is just one widget or a button. Full tree re-evaluation is rare.

- If a component has the _exact_ same `children` prop as before (`===`), as is often the case with e.g. context providers, because it was assigned by a parent, then React will skip re-rendering the children entirely with no effort from the developer.

- If a component is memoized with `memo(...)`, then a re-render will be stopped if it has the same props as before. This means even if your state lives high up in the tree, judicious use of memo can make it zippy af.

TLDR: If your react app is re-calculating the entire tree, you suck at react and you never bothered to learn it. Skill issue, git gud, etc. You're welcome.

Re: Just Fucking Use React

#23

Earlier quoted context omitted.

> Unlike React it doesn't recalculate everything on every mouse move event. Where did you ever get the idea react does this?

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-frequency update, while it's siblings and children remain static.

In this way, React-components are closer to Vue's computed properties than Vue-components.

Re: Just Fucking Use React

#26

Earlier quoted context omitted.

> Unlike React it doesn't recalculate everything on every mouse move event. Where did you ever get the idea react does this?

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…

React can be very performant with little optimization if you apply FP principals to it, which makes sense since it was built with the goal of using FP to do frontend work.

If your whole tree is recalculating on every mousemove event, that is a giant code smell to say the least. You’d have to architect the app to work that way.

Re: Just Fucking Use React

#27
post #12

Why not Vue? Unlike React it doesn't recalculate everything on every mouse move event. Also I would like something that doesn't require to install Node.JS and unly packer like Webpack which invents its proprietary syntax instead of using standard EcmaScript. I like to make small apps that I run by clicking on HTML file and I don't have time to go to console and install things or type commands just to open a webpage.

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.

Re: Just Fucking Use React

#28
Jarring title but 100% agree! You very quickly hit a point building a modern web app where you need advanced functionality. Rolling your own everything in raw javascript is not a sane approach. I think the just use html crowd is composed mainly of backend devs who struggle to comprehend that a web UI is more than just a pretty crud layer on top of their backend. Fight me :)

Re: Just Fucking Use React

#29

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…

React can be very performant with little optimization if you apply FP principals to it, which makes sense since it was built with the goal of using FP to do frontend work. If your whole tree is recalculating on every mousemove event, that is a giant code smell to say the least. You’d have to architect the app to work that way.

FP principle is that functions are first-class objects and one can pass a function to a function. I don't see how it helps programming the UI. Maybe you meant using immutable data structures? I mentioned that and noted that they have their own issues and generally are a pain to use.

> If your whole tree is recalculating on every mousemove event

If you update a variable in the root component, that will happen. Am I wrong?

Re: Just Fucking Use React

#30
post #22

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…

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?

> If your react app is re-calculating the entire tree, you suck at react

The point of UI framework is to do the optimization for me and not require me to use some special style of coding like immutable structures or manually write functions like componentShouldUpdate. What I write is how UI variables depend on model variables and the rest is framework's job. I don't want to use weird patterns like a function with a giant switch that processes update events and clones the whole model graph to change a single variable.

Vue of course has its own set of issues, caused by using proxies (for example when adding on object to the set you must "unwrap" it manually to prevent adding a proxy to the set).

Post reply on HN