Computed
Creating a derived signal
Component('app-counter', () => {
const counter = signal(1);
const doubleCounter = computed(() => counter() * 2)
return () => html`<button>Double of ${counter()} is ${doubleCounter()}</button>`
})<app-counter>
<button>Double of 1 is 2</button>
</app-counter>Component('app-username', () => {
const firstname = signal('John');
const surname = signal('Doe');
const fullname = computed(() => `${firstname()} ${surname()}`)
return () => html`<button>${fullname()}</button>`
})Reacting to computed value changes
Last updated