Skip to content
Justice Tech School

useMemo

useMemo caches a calculated value until dependencies change.

Example
const total = useMemo(() => items.reduce((s, i) => s + i.price, 0), [items]);

Exercise

Cache a value.

(() => calc(), [a])

Quiz Test

What does useMemo cache?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.