DEV Community

Discussion on: Building Web Components with Vanilla JavaScript

thatjoemoore profile image
Joseph Moore

For performance reasons, the browsers require you to define the list of attributes you want to listen to. You can do that by defining a static method called observedAttributes, which returns an array:

static get observedAttributes() {return ['my-attr', 'another-value']; }

That'll cause attributeChangedCallback to fire for changes to either of the listed attributes.

maccabee profile image

Thanks a lot. I did get it to work with a setter but i still wanted to know how the callback works. I'll try it out when I can.