DEV Community

Discussion on: We Should Stop Hating Web Components

Collapse
 
kerryboyko profile image
Kerry Boyko

Honestly, what we need is a standard for web components that allow it to interact with the various frameworks out there, specifically, it should be able to react to changes in attributes, and emit events back to a state manager. I wonder if there's a simple HOF that can make this simple enough.

The reason why this would be a game changer is because every company seems to have it's own branded UI library, making components for React, Vue, or whatever they're using. What would be a game changer is if you could write those components as web components so that each team can choose whether to use them in React OR Vue or whatever framework, essentially allowing companies to avoid vendor lock-in for front-end frameworks.

Collapse
 
theharshsingh profile image
Harsh Singh • Edited

Everything you mentioned above is already implemented in Web Components.

  • A Robust Standard has already been laid out. You can readily use web components in any framework just like any other HTML element. Angular already uses Web Components under the hood.
  • You can observe when a property changes and react to those changes by declaring the attributes you want inside the static get observedAttributes method inside the class and a method called attributeChangedCallback will be invoked every time the attribute changes which will provide you with both its previous and current value so you can compare the changes
  • You can use CustomEvents API for creating and dispatching custom events and you can use any framework agnostic state management library for managing the global state. and for local state you can use getters/setters