Hacker News new | ask | show | jobs
by afavour 1049 days ago
IMO the main reason more people aren’t using Web Components is because React doesn’t support them.

Preact does it just fine so I have to assume it’s possible but simply not in the interests of the React team. React feels like the enterprise lock-in of 2020s development: if you use it you’re using it top to bottom and it’s very difficult to mix and match with other frameworks. It’s a shame.

4 comments

Nobody (meaning very few) care for Web Components, React or not.

Even in frameworks that do support them, they're just not widely used.

Web Components are just an API, a means to an end. You might as easily say nobody cares for document.createElement() but it’s still used by underlying code all the time.

If it were much easier to mix and match components that use different frameworks then people would be using web components whether they know it or not. But we’re in a React monoculture and React folks seem quite content with that.

mm...

Web components aren't 'an' api, it's a specific way of using a set of apis, and specifically requires you to use a set of templates in a way that frameworks (which looovvvveeee DSLs) won't accept.

The other bits? shadow dom? Custom elements? eh. Those are things a framework will wrap happily enough if they see value in it. Maybe some already do? As you say, you'd never know...

...but those html templates will never fly. They're just crazy bad ergonomics and framework authors will never accept them.

That's really the core of the issue; invoking components in your layout requires you to use some kind of layout template, and every framework does it differently.

That's why cross framework css solutions (eg. tailwind) are massively successful, because they can be called easily by anyone regardless of the templating; the same is not... and, frankly, seems like it never will, be true of web components.

They shouldn't be called web components in React (typical JS world term squatting). Instead they should be called React Components.
I personally think more people aren't using WC because React simply exists. I know that sounds controversial, but it isn't.

https://2022.stateofjs.com/en-US/libraries/

Where do you see React doesn’t support web components?.. also many frameworks have wrappers around web components specifically for frameworks like Vue and React for things like passing other values than strings.
In Angular and Vue, their component model nowadays can be mapped into web components directly, it is only a matter of configuration.

React pretends they don't exist.

React supports Web Components, just some quirks to be aware of: https://custom-elements-everywhere.com/