Skip to content

Instantly share code, notes, and snippets.

@eneajaho
Created September 29, 2022 08:07
Show Gist options
  • Save eneajaho/530f8409fe7bee6c92ff32646395b44e to your computer and use it in GitHub Desktop.
Save eneajaho/530f8409fe7bee6c92ff32646395b44e to your computer and use it in GitHub Desktop.
When to use memo
@Component({
selector: "app-root",
template: `
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count) }}</div>
<button (click)="count = count + 1">Increase</button>
`,
standalone: true,
})
export class AppComponent {
count = 0;
isOdd = memo((count: number) => {
console.log('isOdd called');
return count % 2 === 0
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment