Created
September 29, 2022 08:07
-
-
Save eneajaho/530f8409fe7bee6c92ff32646395b44e to your computer and use it in GitHub Desktop.
When to use memo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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