by claytongulick · 1y ago · 0 comments
As a big native web components fan, I've been mystified about the popularity of react.
It, like angular, solved a problem that definitely existed prior to the custom elements spec.
But with custom elements and your favorite rendering library (lit-html, jsx, whatever) I really haven't seen a powerful technical argument for react, other than the ecosystem.
I've had an easier time learning Vue than React, and I've probably spent much longer trying to learn react. And if im not wrong, AI writes better Vue code than react code as well.
Most issues stem from developers refusing to read the docs and to plan their presentation layer.
Might be because mediocre engineers don't read the docs.
Just have each component maintain it's own state. Class setters work great. If you need the component to update, just call render() in the setter.
It's super simple, encapsulates logic, and brain-dead simple to debug. You know exactly where to go for everything: the component.
I've always felt like react's approach to state management was creating more problems than it solves.
One really easy way is to put a custom element at the root of the dom and just add/remove event listeners, maybe one-shot if that's all you need.
I also have a convenient little library called ApplicationState [1], which basically does the same thing but can persist state in indexdb.
Lots of other libraries out there too.
Every react team I've migrated over to WC have picked it up within a couple days, and I've had universally positive feedback on the change.
Also, the web components ecosystem is pretty dang good these days. Between ionic, shoelace, and all the others, there aren't really any functional gaps that I've seen.
I think at this point it just has momentum, and people just go with what they know.
I've never really been a big one for that particular argument though. I've seen the same argument made about Cold Fusion, flash, flex, visual basic, asp server controls, jquery, dojo, moo tools, backbone, and many others.