KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
⚛️

React

Topic Hub & Articles

React Intro

10 min

Recap Quiz

Gated

Milestone Assessment

React Getting Started

10 min

React ES6

10 min

React Render HTML

10 min

Recap Quiz

Gated

Milestone Assessment

React JSX

10 min

React Components

10 min

React Class Components

10 min

Recap Quiz

Gated

Milestone Assessment

React Props

10 min

React Events

10 min

React Conditionals

10 min

Recap Quiz

Gated

Milestone Assessment

React Lists

10 min

React Forms

10 min

React Router

10 min

Recap Quiz

Gated

Milestone Assessment

React Memo

10 min

React CSS Styling

10 min

React Sass Styling

10 min

Recap Quiz

Gated

Milestone Assessment

React Fragments

10 min

React Portals

10 min

React Profiler

10 min

Recap Quiz

Gated

Milestone Assessment

React Strict Mode

10 min

React Higher Order Components

10 min

React Context API

10 min

React Error Boundaries

10 min

What is a Hook

10 min

Recap Quiz

Gated

Milestone Assessment

useState

10 min

useEffect

10 min

useContext

10 min

Recap Quiz

Gated

Milestone Assessment

useRef

10 min

useReducer

10 min

useCallback

10 min

Recap Quiz

Gated

Milestone Assessment

useMemo

10 min

Custom Hooks

10 min

useLayoutEffect

10 min

Recap Quiz

Gated

Milestone Assessment

useImperativeHandle

10 min

useDebugValue

10 min

useDeferredValue

10 min

Recap Quiz

Gated

Milestone Assessment

useTransition

10 min

useId

10 min

Progress
0%

0 / 38 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
ReactReact Hooks
Lesson

useCallback

10 min reading
Free Course

React useCallback Hook: Caching Function Definitions Between Renders

Every time a React component re-renders, functions declared inside its body are recreated as new objects in memory. useCallback caches a function definition between renders so its reference stays identical unless one of its listed dependencies changes.

Two Real Reasons to Use useCallback

  1. Passing Callbacks to React.memo Children: If a parent re-renders and passes an inline handler to a memoized child, the child re-renders anyway because the function reference changed. Wrapping the handler in useCallback keeps the child memoization working.
  2. Stabilizing a useEffect Dependency: If an effect calls a helper function defined inside the component, caching that helper with useCallback avoids re-running the effect on unrelated state updates.
import { memo, useCallback, useState } from 'react';

const FilterButton = memo(function FilterButton({ label, onSelect }) {
  return (
    <button type="button" onClick={() => onSelect(label)}>
      {label}
    </button>
  );
});

export function IssueTracker() {
  const [search, setSearch] = useState('');
  const [activeFilter, setActiveFilter] = useState('open');

  const handleSelect = useCallback((filterName) => {
    setActiveFilter(filterName);
  }, []);

  return (
    <div>
      <input value={search} onChange={(e) => setSearch(e.target.value)} />
      <p>Filter: {activeFilter}</p>
      <FilterButton label="open" onSelect={handleSelect} />
      <FilterButton label="closed" onSelect={handleSelect} />
    </div>
  );
}

How Functional Updaters Shrink Dependencies

Because handleSelect calls setActiveFilter(filterName) without reading activeFilter, its dependency array stays empty ([]). Whenever possible, use functional state setters (setItems(prev => ...)) inside useCallback so the callback rarely needs to be recreated.

Common useCallback Mistakes

  • Using useCallback Without React.memo or useEffect: Wrapping a click handler on a plain <button> adds memory overhead with zero speedup because <button> is not memoized.
  • Omitting Used Values from Dependencies: Leaving out a state variable read inside the callback causes stale closures where the function sees outdated data.

Frequently Asked Questions

What is the difference between useCallback and useMemo?

useCallback(fn, deps) caches the function fn itself so you can call it later. useMemo(() => value, deps) calls the function immediately and caches its return value.

Does useCallback prevent the function from being created in JS syntax?

JavaScript still allocates the inline function argument during render, and useCallback simply returns the previously saved reference when dependencies match.

Does React Compiler remove the need for useCallback?

When using React 19's React Compiler, build-time memoization stabilizes callbacks automatically, though knowing useCallback remains essential for reading and tuning manual React code.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Lesson Recap Quiz Available

Test Your Knowledge

You've completed this section! Take a quick 5-question quiz to check your understanding.

Related Developer Tools & Topic Hub

React Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format JSX/HTML markup
CSS Formatter
Clean and format stylesheets
All React Articles
Deep-dive guides, tips & discussions
PrevioususeReducer
Continue JourneyTake Recap Quiz

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum