You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vinibiavatti1 edited this page Sep 28, 2026
·
4 revisions
Caches the result of a calculation between renders. It will only recompute the memoized value when one of the dependencies has changed.
Note: For lightweight operations, simply compute the value directly in the function component.
import{useState,useMemo}from'react';exportconstMyComponent=()=>{const[products,setProducts]=useState([]);// Lightweight operation (performed for every render)constsortedProducts=lightSort(products);// Heavy operation (performed only when dependencies change)constheavySortedProducts=useMemo(()=>heavySort(products),[products]);// ...};