mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-13 16:04:36 -04:00
fix(curriculum): clarify useMemo rerender behavior (#67350)
Signed-off-by: Caio Bittencourt <caiolucasbittencourt@hotmail.com> Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
This commit is contained in:
@@ -124,9 +124,7 @@ function ExpensiveSquare({ num }) {
|
||||
export default ExpensiveSquare;
|
||||
```
|
||||
|
||||
This will make sure the function is memoized by caching the result, so calculation happens only when the `num` variable changes, not when anything changes in the component it's being used in.
|
||||
|
||||
The `calculateSquare` function call is not running any time `timer` changes anymore but on the initial render and when `num` changes.
|
||||
This will make sure the function is memoized by caching the result. Even though the `ExpensiveSquare` component still re-renders every time the parent's `timer` state updates, the `calculateSquare` computation only re-runs on the initial render and when `num` changes.
|
||||
|
||||
# --questions--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user