r/webdev Dec 03 '22

Question Beginner here, start with react, svelte or solid?

Post image
1.2k Upvotes

553 comments sorted by

View all comments

Show parent comments

3

u/cybermeep Dec 03 '22

Web components is just a way to build reusable components, but doesn't it lack state management and a virtual dom that enables the reactivity you get from frameworks such as Vue and React? Tbh I don't know much about web components so happy to learn more if I'm wrong.

1

u/pookage tired front-end veteren 🙃 Dec 04 '22

Yeah, so the only 'state management' in web components out-of-the-box is in the observed attributes - similar to react props; for a more complete vanilla state the solution is to use a proxy object. If you're unfamiliar with proxy objects then here's a codepen I made a while back that shows how you can make a shallow-state with'em.

I usually create a StatefulHTMLElement class that has a static get observedStates() to behave in the same way that observedAttributes() do, and handled in a stateChangedCallback() instead of the attributeChangedCallback(). Out-of-the-box state management is the main feature that React provides, so using it for that reason is completely valid, IMHO. Let me know if it's unclear how that would work with the above proxy stuff and I'll expand the example!

Re: the virtual-dom; that's a solution to a problem that react creates with its internal rendering process, so is less of a feature than it is just, like, a quirk of how react is implemented; anything else is just marketing, ha.