46
Main Concepts
Hooks function Counter() {
const memoizedValue = useMemo(() => {
// computeExpensiveValue is a function with heavy calculation
return computeExpensiveValue(count)
}, [count])
return (
<>
Computation result: {memoizedValue}
setCount(count + 1)}>
Clicked {count} times
>
)
}
● useMemo
returns a
memoized value,
it only recomputes
when one of the
dependencies has
changed