diff --git a/src/exercise/02.md b/src/exercise/02.md index 18f5b184..73aba749 100644 --- a/src/exercise/02.md +++ b/src/exercise/02.md @@ -10,8 +10,8 @@ Elaborate on your learnings here in `src/exercise/02.md` Memoization: a performance optimization technique which eliminates the need to recompute a value for a given input by storing the original computation and -returning that stored value when the same input is provided. Memoization is a form -of caching. Here's a simple implementation of memoization: +returning that stored value when the same input is provided. Memoization is a +form of caching. Here's a simple implementation of memoization: ```typescript const values = {} @@ -122,7 +122,7 @@ React.useEffect(() => { }, [updateLocalStorage]) // <-- function as a dependency ``` -The problem with that though it will trigger the `useEffect` to run every +The problem with doing that is that it will trigger the `useEffect` to run every render. This is because `updateLocalStorage` is defined inside the component function body. So it's re-initialized every render. Which means it's brand new every render. Which means it changes every render. Which means... you guessed @@ -227,8 +227,8 @@ some fancy things with dependencies (dependency arrays are the biggest challenge to deal with when making custom hooks). NOTE: In this part of the exercise, we don't need `useCallback`. We'll add it in -the extra credits. It's important that you work on this refactor first so -you can appreciate the value `useCallback` provides in certain circumstances. +the extra credits. It's important that you work on this refactor first so you +can appreciate the value `useCallback` provides in certain circumstances. ## Extra Credit @@ -305,7 +305,12 @@ function that people can call in their own `useEffect` like this: ```javascript // πŸ’° destructuring this here now because it just felt weird to call this // "state" still when it's also returning a function called "run" πŸ™ƒ -const {data: pokemon, status, error, run} = useAsync({ status: pokemonName ? 'pending' : 'idle' }) +const { + data: pokemon, + status, + error, + run, +} = useAsync({status: pokemonName ? 'pending' : 'idle'}) React.useEffect(() => { if (!pokemonName) {

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /