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