Chapter 3. Making your component reusable

This chapter covers

  • Using getters and setters to work with data in your component
  • Using attributeChangedCallback to listen for attribute changes
  • Identifying which attributes to listen for changes on using observedAttributes
  • Working with attributes using hasAttribute() getAttribute(), and setAttribute()

In the last chapter, we talked in great depth about simple ways to create your first Web Component. Specifically, we looked at creating your own custom element and assigning some minimal custom logic so your component acts a certain way. But what if you want your component to act differently depending on what parameters you use to set it up? What if you want your component to be adaptable? Usually, ...

Get Web Components in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.