Dan Abramov 6 years ago
parent
commit
26b0eb258a
  1. 2
      content/docs/hooks-faq.md

2
content/docs/hooks-faq.md

@ -343,7 +343,7 @@ const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
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. 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.
**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.) **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* be recomputed, you can [lazily initialize](#how-to-create-expensive-objects-lazily) a ref.)
Conveniently, `useMemo` also lets you skip an expensive re-render of a child: Conveniently, `useMemo` also lets you skip an expensive re-render of a child:

Loading…
Cancel
Save