[React.js] UseMemo Hook
This sample shows that normal onChange function and using useCallback hook. useCallback will returns a memorized callback to prevent unnecessary renders.
// assume that you have setNumber function
const onChange = (e) => {
setNumber(e.target.value);
};
// with callback
const onChange = useCallback((e) => {
setNumber(e.target.value);
}, []); // [] will create function only on firsttime
Official Document
Comments