Skip to content

Instantly share code, notes, and snippets.

@eneajaho
Created September 29, 2022 08:03
Show Gist options
  • Save eneajaho/036cbce9c5f78b688bd3aa8c848ce6f3 to your computer and use it in GitHub Desktop.
Save eneajaho/036cbce9c5f78b688bd3aa8c848ce6f3 to your computer and use it in GitHub Desktop.
When not to use memo
@Component({
selector: "app-root",
template: `
<div>{{ isOdd(count) }}</div>
<div>{{ isOdd(count + 1) }}</div>
<div>{{ isOdd(count + 2) }}</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