Last week, Ryan Carniato, the guy who made SolidJS, wrote an article about how Web Components are not the future. The nicest thing I can say about it is that he's just completely, utterly wrong. His article really boiled down to "Web Components are hard for me as a library author to implement, and I don't like that." Rather than do a deep analysis on it, I'll instead point you to Cory LaViska's rebuttal, and Nolan Lawson's follow-up. They both responded in far more thorough and thoughtful ways than I have the time for at the moment. And if you want a pithy response, I think Jeremy Keith did that better than I could have, too…
What I actually wanted to talk about today was the role of Web Components in your site or app. Early on, Google positioned Web Components as a native replacement for stuff like React. And as Jeremy's quote above alludes… they're not! They do very different things, very differently. Web Components are not, in my opinion, good at building an entire UI. In particular, I think patterns like what you see in Shoelace (now being built out as Web Awesome) are an anti-pattern, where this…
Renders this…
For starters, you now have a basic HTML element that only renders with JS, but that JS is not adding any interactivity to the element. It's only purpose is to hide how the sausage is made and obfuscate all of the classes and nested HTML that gets added. This is a very React-like approach to Web Components. And frankly, state-based UI libraries do it better. Where Web Components really shine is when you want to add interactivity to or enhance existing DOM nodes. Specifically, anything that you could build with jQuery or vanilla JS DOM manipulation, Web Components make easier. One of my favorite examples is a taking a collection of headings and content, like this…
And progressively enhancing it into an accordion component, with the appropriate event listeners, ARIA attributes, and so on. You could do the same thing without it, but Web Components make it easier. I have a bunch of examples and an entire course on how to build Web Components like this over at the Lean Web Club. In my mind, a good site or app design system is mostly HTML and CSS, with Web Components for progressively layering in interactivity. Cheers, Want to share this with others or read it later? View it in a browser. |
0 Komentar untuk "[Go Make Things] The role of Web Components in your site or app"