function Button({ color, children }) {
const textColor = useMemo( () => slowlyCalculateTextColor(color), [color] // ✅ Don’t recalculate until `color` changes ); return (
<button className={'Button-' + color + ' Button-text-' + textColor}>
{children}
</button>
);
}
const memoizedCallback = useCallback(
() => {
doSomething(a, b);
},
[a, b],
);
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
useCallback(fn, deps)
is equivalent to useMemo(() => fn, deps)
.
Comments
Post a Comment