|
|
|
|
|
by incrudible
1048 days ago
|
|
> You can simply watch for HTMLElement attribute changes You know what's really, really, really slow? Anything involving the DOM, reading, writing, whatever. > often leads to unnecessary double or triple rendering "Renders" on the other hand are very cheap if they don't actually touch the DOM. |
|
React renders aren't always cheap. It depends on the complexity of the component and you don't have as much control over the rendering. I've worked on some React apps which were so slow due to unnecessary re-renders that my new computer would often freeze during development. I was able to fix it by refactoring the code to be more specific with useState() (to watch individual properties instead of the entire object) but this flexibility that useState provides is a React footgun IMO. With HTMLElement, you're forced to think in terms of individual attributes anyway and these are primitive types like strings, booleans or numbers so there is no room for committing such atrocities.