In JavaScript, a function() {} or () => {} always creates a different function, similar to how the {} object literal always creates a new object. Normally, this wouldn’t be a problem, but it means that props receiving this function will never be the same, and your memo optimization won’t work. This is where useCallback comes in handy:
useCallback is a React Hook that lets you cache a function definition between re-renders.
By default, when a component re-renders, React re-renders all of its children recursively.
Skipping re-rendering of components: to cache the functions that you pass to child components. As function is defined on every render thus rendering all children in the component tree recursively.
Updating state from a memoised callback
Preventing an Effect from firing too often: When a function is passed as a dependency of an effect hook.
Optimising a custom Hook: If you’re writing a custom Hook, it’s recommended to wrap any functions that it returns into useCallback
You have a parent component that passes a callback prop to a child that renders a list. How would you use useCallback to prevent the child from re‑rendering unnecessarily?
If you forget to include a value in the dependency array of useCallback, what could happen when that value changes?
Show me how you'd wrap an event handler with useCallback in a functional component that fetches data on button click.
We added useCallback to memoize a fetch function, but the component still makes API calls on every render. Walk me through how you'd debug this.
When would you decide not to use useCallback even if a child component is wrapped with React.memo?
Explain the trade‑offs of using useCallback for a large list of items where each item receives its own memoized handler.
In a complex dashboard with dozens of widgets, each receiving callbacks via context, how would you structure useCallback usage to keep re‑renders minimal while avoiding stale closures?
Describe how you’d profile the performance impact of useCallback across a high‑traffic page and decide whether to keep or remove it.
If a library you depend on expects stable function references but you also need to capture changing props, how would you design the hook usage to satisfy both?
Our team is migrating a legacy codebase that heavily recreates functions each render. How would you create a shared utility or pattern around useCallback to improve maintainability across multiple squads?
When designing a component library that will be used by many teams, what guidelines would you set for when to expose props that require callers to wrap callbacks with useCallback?
Consider a micro‑frontend architecture where callbacks are passed across bundle boundaries. What are the implications of useCallback on bundle size and runtime behavior, and how would you address them?