4 ms·
I can't make comparisons to Angular as I've never used that library. However, the point of React and the many virtual DOM libraries like it is to simplify UI co
by rspeele 10y ago
I can't make comparisons to Angular as I've never used that library. However, the point of React and the many virtual DOM libraries like it is to simplify UI code.
You write a function that takes the current model state and returns the DOM tree that should be displayed in that state. If you want to change something on the UI, you swap in a new state and the whole thing is re-rendered -- at least that's the abstraction.
It's a programming model that's easy to understand and hard to get wrong. That's the great thing about it! The bad thing about it is that if you implemented it naively, by actually re-rendering all the HTML for your single-page app on every state change, the performance would be awful.
Virtual DOM diffing is a solution to that performance problem, and it makes applications written this way perform adequately. You can't read about React without the DOM diffing being mentioned, and library authors love to compare benchmarks, so it's easy to see virtual DOM as the feature. It's just a means to an end though.