Usecallback in react

useCallback is a hook that returns a memoized version of a callback function. It only changes if one of its dependencies changes. This is critical when passing functions to child components optimized with React.memo, ensuring the function's identity remains stable across renders.

Example

const handleSave = useCallback(() => {
  saveData(data);
}, [data]);