Hacker News new | ask | show | jobs
by _boffin_ 1253 days ago
I’ve been playing with webcomponents for a month or two and really love them. I do wish that IntelliJ would play nice with the formatting of them though.

Question: when and or if they gain in adoption, could you see them replacing react? If not, what’s the use-cases that you believe they wouldn’t work for?

2 comments

Anywhere you actually need React (and also React lite solutions like Preact or Alpine), which is essentially where your page isn't just a static page, web components by themselves don't do anything to handle the complexity of state. But what they allow you to do is to use the same component in whatever framework you pick.
Yeah, what I like about React is how declarative component writing is, and how you delegate state changes to escape hatches. Plain old HTML is supposed to be declarative but updating with vanilla JS quickly gets you into the weeds.

I tried to get into WebComponents, but the MDN tutorial has you writing a lot of `document.createElement` and `document.appendChild`, which is the sort of imperative stuff I don't like about vanilla JS DOM manipulation.

> delegate state changes to escape hatches

Ay.

Can you please explain what this means in simple, 5th grader English?

React says what things should be, given a limited state. (These elements read X, and update when X changes.)

Vanilla JS says how to do things (find these HTML elements and update them by doing X).

It is much simpler to track and mutate a state object, than it is to find all the nodes you need to update and update appropriately.

IMO they are complimentary to react.

Frameworks like react/angular/backbone/vue solve the problem of creating a single page application with a nice architecture and sharing code between components within the SPA.

Web components solve the problem of sharing code between any application.

There are opportunities to share code (eg/ data binding) and I believe that is the case (they use the same underlying browser APIs where available)

With exception of React, all those frameworks have options to generate WebComponents for their component model.
That is cool, didn't realize that! I wonder why React lags behind ( ? )
I think it is a culture issue, as far as I understand the underlying issue, the React community is not so impressed with having to deal with Web Components.
Realistically, there's almost no community that is impressed with having to deal with Web Components.

In this discussion I keep reiterating: there are multiple reasons why none of the major frameworks and very few of the new frameworks have WCs as their foundation. At best they can consume/embed them and perhaps compile to them. And even that is rife with problems.

If we ignore the fact that everyone else supports them, regardless if they are their foundation or not.

https://custom-elements-everywhere.com/

Web components seem like a good idea to me. I would imagine there are a lot of libraries out there (eg/ calendars, styling frameworks) that would benefit from reuse across applications. The browser could cache it even if served from a different CDN.

I'm curious what the problems are with web components that you see? Is it specifically related to how they might be used (or useless) in the major frameworks?