MENU
Difference with useCallback()
Unlike the return value of a call to a callback passed to useCallback, the return value of the callback passed to useMemo is memoized.
RESETRUNFULL
RESETRUNFULL
function Example(){
const [a,setA] = React.useState(0);
const m = React.useMemo(() => Math.random(),[]);
const n = React.useCallback(() => Math.random(),[]);
setTimeout(()=>{setA(a=>a+1);},1000);
return (<React.Fragment>
<button>{m} (static)</button>
<button>{n()} (changing)</button>
</React.Fragment>);}ReactDOM.render(<Example/>,document.querySelector("div"));