質問
We would like to introduce use-Memo which is build-in method in React.js.
Update: 

What is use-memo

const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);

It returns a memoized value.

  • 1st argument : function ( e.g.() => computeExpensiveValue(a, b) )
  • 2nd argument ( e.g. [a, b] )

useMemo will only recompute the memoized value when one of the dependencies has changed. This optimization helps to avoid expensive calculations on every render.

Write a comment

Purpose to use use-memo

  • If a calculation was not quite complex, we should not use use-memo due to the overhead of use-memo.
  • use-memo maintains variable objects, so it is helpful to avoid re-rendering when not needed.
Write a comment

Confirm by Profiler of React Developer Tools

Make sure to profile the component with and without use-memo. Only after they conclude whether memoization is worth it.

When memoization is misused, it could harm the performance.

Write a comment
この記事が気に入ったら応援お願いします🙏
5
ツイート
LINE
Engineer
morizyun
Full stack developer. Be able to build an optimal architecture with Next.js / Firebase / TypeScript / JavaScript Ruby / Golang / Kotlin / Java.