by bastawhiz · 3y ago · 0 comments
Array.from(document.querySelectorAll('.foo')).forEach(el => el.style.display = 'none');
Being able to select something, then chain operations on those nodes is really where jQuery shines, IMO. All of the non-DOM stuff (e.g., AJAX) is fine with vanilla JS these days. document.querySelectorAll('.age').forEach(el => el.style.display = 'none')
But I didn't have to do anything like that in years. With reactive frameworks you just bind visibility and styles to variables, refs or some central state.I fail to see the superiority of that approach after more than a decade.
To me, the success of React and the likes has more to do with team dynamics, hiring, etc.
Essentially it's declarative programming, you declare your UI should look this way when the state is this, and that way when the state is that.
It's much easier to reason about than when you have a thousand random functions that can change the UI, often in ways that break each other.
I can separate concerns instead of multiple functions changing the same UI, but I can’t guarantee that everyone else will.
The conventions that React provides sidesteps the need for discipline and that I find useful.
Doesn’t mean that the approach in itself is better, IMO. and if you work alone, it’s clearly way too much trouble for little gain.
some-selector .foo {
display: none;
}I don't know why querySelectorAll() doesn't just return an array.