# Web Component Base This is a very minimal base class for creating reactive custom elements easily. When you extend the `WebComponent` class for your component, you only have to define the `template()` and `observedAttributes()`, and changes in any attribute value will automatically cause the UI to render. The result is a reactive UI on attribute changes. ## Installation ```bash npm i web-component-base ``` ## Usage In your component class: ```js // HelloWorld.mjs import WebComponent from "web-component-base"; export class HelloWorld extends WebComponent { name = "World"; emotion = "excited"; static get observedAttributes() { return ["name", "emotion"]; } get template() { return `
### Hooks
Currently, you can define behavior when an attribute value changes by defining a method `onChanges` in your component:
```js
import WebComponent from "../index.mjs";
export class HelloWorld extends WebComponent {
name = "World";
emotion = "excited";
static get observedAttributes() {
return ["name", "emotion"];
}
onChanges({ previousValue, currentValue }) {
console.log(">>> changed", { previousValue, currentValue });
}
get template() {
return `