Skip to content

Commit 9b5638f

Browse files
authored
Tweak useMemo wording (#1569)
* Tweak useMemo wording * Update hooks-faq.md * Update hooks-reference.md * Be more specific
1 parent 1a49812 commit 9b5638f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

content/docs/hooks-faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ See also [the recommended pattern for derived state](#how-do-i-implement-getderi
282282

283283
### How do I implement `getDerivedStateFromProps`?
284284

285-
While you probably [don't need it](/blog/2018/06/07/you-probably-dont-need-derived-state.html), for the rare cases that you do (such as implementing a `<Transition>` component), you can update the state right during rendering. React will re-run the component with updated state immediately after exiting the first render so it wouldn't be expensive.
285+
While you probably [don't need it](/blog/2018/06/07/you-probably-dont-need-derived-state.html), in rare cases that you do (such as implementing a `<Transition>` component), you can update the state right during rendering. React will re-run the component with updated state immediately after exiting the first render so it wouldn't be expensive.
286286

287287
Here, we store the previous value of the `row` prop in a state variable so that we can compare:
288288

@@ -343,7 +343,7 @@ const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
343343

344344
This code calls `computeExpensiveValue(a, b)`. But if the inputs `[a, b]` haven't changed since the last value, `useMemo` skips calling it a second time and simply reuses the last value it returned.
345345

346-
`useMemo` is treated as a hint rather than guarantee. React may still choose to "forget" some previously memoized values to free memory, and recalculate them on next render.
346+
**You may rely on `useMemo` as a performance optimization, not as a semantic guarantee.** In the future, React may choose to "forget" some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo`and then add it to optimize performance. (For rare cases when a value must *never* recomputed, you can [lazily initialize](#how-to-create-expensive-objects-lazily) a ref.)
347347

348348
Conveniently, `useMemo` also lets you skip an expensive re-render of a child:
349349

content/docs/hooks-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Pass a "create" function and an array of inputs. `useMemo` will only recompute t
290290

291291
If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument. (With an inline function, on every render.)
292292

293-
**Don't rely on `useMemo` for correctness.** React treats it as an optimization hint and does not *guarantee* to retain the memoized value. For example, React may choose to "forget" some previously memoized values to free memory, and recalculate them on next render.
293+
**You may rely on `useMemo` as a performance optimization, not as a semantic guarantee.** In the future, React may choose to "forget" some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo`and then add it to optimize performance.
294294

295295
> Note
296296
>
@@ -383,4 +383,4 @@ function useFriendStatus(friendID) {
383383

384384
> Tip
385385
>
386-
> We don't recommend adding debug values to every custom hook. It's most valuable for custom hooks that are part of shared libraries.
386+
> We don't recommend adding debug values to every custom hook. It's most valuable for custom hooks that are part of shared libraries.

0 commit comments

Comments
 (0)