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

useMemo

10 min reading
Free Course

React useMemo Hook: Memoizing Expensive Derived Values

useMemo caches the computed result of a function between re-renders. During each render, React checks the dependency array; if none of the values changed, React reuses the saved result instead of running a slow sort, filter, or aggregation again.

Caching Expensive Computation and Object References

useMemo solves two distinct problems: skipping heavy CPU work (like filtering 10,000 table rows) and keeping a derived object or array's memory reference stable when passing it to a React.memo child or useEffect.

import { useMemo, useState } from 'react';

export function ProductCatalog({ products }) {
  const [query, setQuery] = useState('');
  const [darkMode, setDarkMode] = useState(false);

  const visibleProducts = useMemo(() => {
    const term = query.trim().toLowerCase();
    return products
      .filter((item) => item.name.toLowerCase().includes(term))
      .sort((a, b) => a.price - b.price);
  }, [products, query]);

  return (
    <section className={darkMode ? 'dark' : 'light'}>
      <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Filter..." />
      <button type="button" onClick={() => setDarkMode((d) => !d)}>Toggle Theme</button>
      <p>Showing {visibleProducts.length} items</p>
    </section>
  );
}

Toggling darkMode re-renders ProductCatalog, yet visibleProducts does not re-filter or re-sort because products and query stayed unchanged.

Common useMemo Mistakes

  • Wrapping Cheap Expressions: Wrapping a + b or formatting a short string in useMemo wastes memory and hurts readability because running the dependency check costs more than the calculation itself.
  • Running Side Effects Inside useMemo: useMemo runs during rendering and must remain pure. Never call state setters, DOM mutations, or fetch inside useMemo.
  • Trusting useMemo as a Permanent Cache: React may discard cached values to free memory in future concurrent features, so only use useMemo as a performance optimization, not for correctness.

Frequently Asked Questions

How do I know if a calculation is slow enough for useMemo?

Measure it with console.time or the React DevTools Profiler. Generally, calculations taking under 1 millisecond do not need manual useMemo.

Can useMemo stabilize a Context Provider's value object?

Yes. Wrapping useMemo(() => ({ user, logout }), [user]) prevents unnecessary re-renders across every consumer whenever the Provider's parent updates.

What happens if the dependency array is empty ([])?

React computes the value once when the component mounts and keeps returning that exact value until the component unmounts.

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

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
PrevioususeCallback
Continue JourneyNext: Custom Hooks

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum