MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
The useCallback Hook and Stabilizing Callback Props0%
Study Materials
React.js for IntermediateProgress 0%
1.1Component Reusability and Polymorphic Components1.2Render Props Pattern in Modern React1.3Higher-Order Components vs Modern Hooks1.4Compound Components Pattern Explained
8.1React Re-render Rules and Profiling Bottlenecks8.2Memoizing Components with React memo8.3The useCallback Hook and Stabilizing Callback Props8.4The useMemo Hook and Expensive Computations
HomeTutorialsReact.js for IntermediateThe useCallback Hook and Stabilizing Callback Props
The useMemo Hook and Expensive Computations

The useCallback Hook and Stabilizing Callback Props

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Problem of Re-created Functions

In JavaScript, functions are first-class objects. Every time a component executes its render cycle, any function declared inside that component's body is re-instantiated as a brand new object in memory:

1// On Render 1:
2const fn1 = () => console.log('clicked');
3 
4// On Render 2:
5const fn2 = () => console.log('clicked');
6 
7console.log(fn1 === fn2); // FALSE! Distinct memory addresses!

If you pass this function down as a prop to a child component wrapped in React.memo, the child will re-render on every parent render, because React sees a different function reference every time!

2. What is useCallback?

useCallback is a React hook that caches a function definition between renders. It returns the exact same function reference across renders unless one of its dependencies changes.

1useCallback(fn, dependencies)
2 ├─ Dependencies unchanged? ──► Returns cached function reference from previous render!
3 └─ Dependencies changed? ──► Re-creates function and caches new reference!

3. Practical Example: Stabilizing Callbacks for Memoized Children

Consider a parent with an expensive list of items:

1import React, { useState, useCallback, memo } from 'react';
2 
3// 1. Expensive child component wrapped in React.memo
4const StudentRow = memo(function StudentRow({ student, onRemove }) {
5 console.log(`Rendering row: ${student.name}`);
6 return (
7 <li className="student-row">
8 <span>{student.name}</span>
9 <button onClick={() => onRemove(student.id)}>Remove</button>
10 </li>
11 );
12});
13 
14export default function StudentRoster() {
15 const [students, setStudents] = useState([
16 { id: 1, name: 'Rahul' },
17 { id: 2, name: 'Priya' },
18 { id: 3, name: 'Aman' }
19 ]);
20 const [theme, setTheme] = useState('light');
21 
22 // ❌ Without useCallback: handleRemove would get a new reference every time 'theme' toggles!
23 // ✅ With useCallback: reference is STABLE across all renders!
24 const handleRemove = useCallback((id) => {
25 setStudents((prev) => prev.filter((s) => s.id !== id));
26 }, []); // Empty deps because functional update 'setStudents(prev => ...)' needs no external state!
27 
28 return (
29 <div className={`roster theme-${theme}`}>
30 <button onClick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}>
31 Toggle Theme
32 </button>
33 
34 <ul>
35 {students.map((student) => (
36 <StudentRow
37 key={student.id}
38 student={student}
39 onRemove={handleRemove} // Stable reference passed!
40 />
41 ))}
42 </ul>
43 </div>
44 );
45}

Now, when you click "Toggle Theme":

  1. 1
    StudentRoster re-renders to update the theme.
  2. 2
    handleRemove retains its exact same cached reference.
  3. 3
    StudentRow checks its props: student is identical, and onRemove is identical.
  4. 4
    All <StudentRow> components skip re-rendering entirely!

4. The Golden Pair: useCallback + React.memo

Remember: useCallback does not make function creation faster.

In fact, calling useCallback has a slight overhead (allocating arrays and comparing dependencies).

useCallback is only useful when:

  1. 1
    Passing callbacks to memoized child components (React.memo).
  2. 2
    Passing callbacks as dependencies to other hooks (e.g. inside a useEffect dependency array).

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary purpose of the useCallback hook in React?
Question 2
Why does useCallback have little benefit if the child component receiving the function is NOT wrapped in React.memo?
Question 3
How does combining useCallback with functional state updates (setCount(prev => prev + 1)) help dependency arrays?
Question 4
When is useCallback necessary inside a useEffect workflow?
Question 5
What does useCallback(fn, deps) return?
Next Lesson

The useMemo Hook and Expensive Computations

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Memoizing Components with React memoThe useMemo Hook and Expensive Computations

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext