Capítulo 49 de 116
useCallback(fn, dependencies) returns the same function reference across renders as long as the listed dependencies haven't changed, letting a function be passed to a memoized child (memo) or an Effect's dependency array without causing unnecessary re-renders/re-runs purely because a new closure was created.
memo's prop-equality check and forces Effects that depend on that function to re-run every time.const cachedFn = useCallback(fn, [deps]) — React caches fn and returns the cached version unless a dependency changed since the last render, mirroring useMemo's dependency-array semantics.useCallback(fn, deps) is equivalent to useMemo(() => fn, deps) — it's a convenience specifically for the function-caching case, not a fundamentally different mechanism.useCallback "just in case" adds overhead without benefit if nothing consuming that function actually depends on stable identity (no memoized child receiving it as a prop, no Effect depending on it).useCallback manually.const handleSubmit = useCallback((orderId) => {
post('/orders', { orderId, productId });
}, [productId]); // stable reference unless productId changes
productId.useCallback when a function is passed to a memo-wrapped child or used as an Effect dependency — not as a default wrapper for every function.fn is still evaluated) — it only affects which reference gets returned and cached.useCallback calls remain valid.