Repository navigation
useCallback
vinibiavatti1 edited this page Sep 28, 2026
·
2 revisions
By default, React re-creates function definitions on every render. useCallback caches a function definition between renders, returning the exact same function instance as long as its dependencies do not change.
Note: Typically used to pass stable function references to
React.memocomponents or asuseEffectdependencies.
import { useEffect, useCallback } from 'react';
const Component = () => {
// Preserved function reference across re-renders
const fetchData = useCallback(() => {
fetch('/api').then(...);
}, []);
// Prevents infinite re-triggering since fetchData maintains a stable reference
useEffect(() => {
fetchData();
}, [fetchData]);
};- Home
- Functional Components
- Props
- Fragments
- Memoization
- Forward Ref
- Portals
- Suspense
-
Hooks
- State
- Context
- Effect
- Ref
- Performance
- Concurrent
- Form
- Utility
- Custom Hooks