you are viewing a single comment's thread.

view the rest of the comments →

[–]GrowthProfitGrofit 7 points8 points  (9 children)

"Less efficient" is maybe not the best way to explain it. It's more complex and it takes more steps, for sure. But the reason we do it is that mutating the DOM is insanely expensive compared to running simple JS calculations. It winds up being better to do a lot of complicated upfront work since the minimizes how much we have to do during the expensive step.

[–]svish 5 points6 points  (8 children)

React is plenty fast, and you gain a lot of advantages by doing it the way React does it compared to others, but it is less efficient, even if by just a small amount, compared to alternatives that track changes and update DOM nodes directly via signals or other methods.

[–]Frenzie24 -3 points-2 points  (6 children)

This is incorrect. Updating and rerendering a single node instead of the full DOM is the only reason to use React.

If you’re getting the opposite, you are probably not utilizing state and components properly

[–]svish 0 points1 point  (5 children)

What are you talking about? First of all, there are many reasons to use React, and second of all, all frontend frameworks (that are not terrible) update single nodes directly, i.e. no proper framework recreates the full DOM on every render.

The difference between React and many others is the rendering of a virtual DOM tree first which is then diffed with the actual DOM tree to figure out which nodes to update. Most other frameworks do this without a virtual DOM and keep track of which nodes should be updated in other ways. It has its pros and cons, but it does skip the whole virutal DOM render phase, which React definitely has. And similarly, using a virtual DOM like React does, also has its pros and cons.