Optimize expensive operations with React useMemo hook

InstructorTomasz Łakomy

Share this video with your friends

Send Tweet

When using functional components in React we may run into situations where we are performing expensive calculations multiple times, even though the values passed in to the functional component hasn't changed.

This is where useMemo hook comes in. In this lesson we are going to learn how to use useMemo hook to optimize an expensive (in this example - highly expensive operation of adding two numbers together, for simplicity) operation so that its result is recalculated only when it's necessary - that is, when the input arguments have changed. Otherwise, we are going to use an optimized, memoized result.