React Hooks: How to use the useMemo React hook

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Check out my React hooks introduction first, if you’re new to them.

One React hook I sometimes use is useMemo.

import React, { useMemo } from 'react'

This hook is used to create a memoized value.

This hook is very similar to useCallback, the difference is that useCallback returns a memoized callback and useMemo returns a memoized value, the result of that function call. The use case is different, too. useCallback is used for callbacks passed to child components.

Sometimes you have to compute a value, either through a complex calculation or by reaching to the database to make a costly query or to the network.

Using this hook, this operation is done only once, then the value will be stored in the memoized value and the next time you want to reference it, you’ll get it much faster.

Here’s how to use it:

const memoizedValue = useMemo(() => expensiveOperation())

Make sure you add that empty array as a second parameter to useMemo(), otherwise no memoization will happen at all.

If you need to pass arguments, you also need to pass them in the array:

const memoizedValue = useMemo(() => expensiveOperation(param1, param2), [param1, param2])

If one of the parameters change when you try to access the value, the value of course will be calculated without memoization.

Lessons in this unit:

0: Introduction
1: Introduction to React Hooks
2: How to use the useState React hook
3: useEffect React hook, how to use
4: How to use the useContext React hook
5: How to use the useReducer React hook
6: How to use the useCallback React hook
7: ▶︎ How to use the useMemo React hook
8: How to use the useRef React hook
9: Can I use React hooks inside a conditional?
10: Why does useEffect run two times?
11: Using useState with an object: how to update
12: How to reference a DOM element in React