←back to thread

367 points lemonberry | 3 comments | | HN request time: 0.873s | source
Show context
verisimilidude ◴[] No.24641789[source]
Fully agree with the author.

My biggest complaint about web components is that I don’t see a lot of advantages over using React, Svelte, or some other JS library. The author hints at this: if I’m already committing to a big JS build process, why wouldn’t I reach for one of these more ergonomic JS tools? Warm fuzzies for trying to use open standards isn’t enough to convince most people to switch away from more popular JS solutions.

replies(4): >>24641859 #>>24641900 #>>24642049 #>>24644957 #
onion2k ◴[] No.24641900[source]
One huge advantage is that you can isolate a web component in its own shadow DOM, which means it has CSS that's independent from the rest of the page. If you're making something for other people to embed in their code, even if you're on the same project, you can save them from breaking it by styling it by mistake.

You can also close the shadow DOM to stop people easily inspecting it, but I must admit I haven't actually figured out a reason to do that yet.

replies(2): >>24642044 #>>24643212 #
franciscop ◴[] No.24642044[source]
That is the same if you use e.g. styled components with React, where every component is self-contained and doesn't leak the styles. The mechanism is different, but the end result is the same, and oh it's a game changer IMHO.
replies(3): >>24642885 #>>24644998 #>>24650604 #
1. goatlover ◴[] No.24642885[source]
But why should developers have to use a framework like React to do something the browser could provide for them? Not everyone is writing a JS application. Some just need to add some custom HTML, CSS and little bit of JS.
replies(1): >>24643250 #
2. trufas ◴[] No.24643250[source]
I don't think the GP was arguing against that. If you're already committed to an existing build process building new components as web components doesn't really have many advantages vs a component built in react. It's just adding needless complexity.
replies(1): >>24647993 #
3. onion2k ◴[] No.24647993[source]
Web components can be built separately to the rest of an application as standalone components and included by adding a <script> tag, and then using them is as straightforward as using an HTML tag. You need a build process for the component (or the author of the component does..) but you don't need one for the website you're using it in. You can do that with a React component as well but you don't get the benefits of things like styled components if you do. You do with web components.