|
|
|
|
|
by Spivak
1798 days ago
|
|
The problem with React (or the reason you might want to sometimes choose VanillaJS) is that React's algorithm to apply a DOM diff has to be completely generic. In React your flow will loosely be Something happens
The browser triggers and event and sends it to React
React calls your code to re-render the world[1]
React takes the new world order and does a diff
React calculates what to do go from old -> new and applies
In VanillaJS world you can do way way way better than this with the benefit of knowing how your application works. Something happens
The browser triggers and event and sends it to your handler
Your handler updates the DOM
It would be nice if in future you could make some promises to React about what happens on an event so React can skip the diffing step and just update the virtual and real DOM directly. And hint hint if you can generate the code to update the DOM directly in the general case too then do you even need the virtual DOM? Svelte is doing really cool work in this space.[1] componentDidUpdate helps but same diff |
|
I'm glad it's not easy to escape the paradigm.
I know there are cases where it's needed but it's rare (at least in my line of work).