Created
September 29, 2022 08:03
-
-
Save eneajaho/036cbce9c5f78b688bd3aa8c848ce6f3 to your computer and use it in GitHub Desktop.
When not 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 + 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