Effect Hook

It is how useEffect hook would look in Angular.

🔥Effect Hook in Template

An example in COMPONENT.component.ts.

@Component({
  selector: 'app-use-effect',
  templateUrl: './use-effect.component.html'
})
class Host {
  effect() {
    console.log('Lol');
    return () => {
      console.log(`I'm died!`);
    };
  }
}

An example in COMPONENT.template.html.

<ng-container *useEffect="effect; on [x]">
  Hello world!
</ng-container>

🔥 Effect Hook with Ivy

An example in COMPONENT.component.ts.

function effect() {
  console.log('Lol');
  return () => {
    console.log(`I'm died!`);
  };
}

@Component({
  selector: 'app-use-effect',
  template: ''
})
@UseEffect(effect, ['x'])
class Host {
  public x: string;
}

Last updated