State Hook

It is how useState hook would look in Angular.

📌 State Hook in Template

An example in COMPONENT.template.html.

<div *useState="let x default 0">
  <button (click)="x = x + 1">Press me: {{x}} 🔥</button>
</div>

📌 State Hook with Ivy

An example in COMPONENT.component.ts.

const initialValue = 0;

@Component({
  selector: 'app-use-state',
  template: `
    <button (click)="setCount(count + 1)">
      Press me: {{count}} 🔥
    </button>
  `
})
@UseState(['count', 'setCount'], initialValue)
class Host {}

Last updated