Skip to content
Learn Netverks

Lesson

Step 29/36 81% through track

usememo-usecallback

useMemo and useCallback

Last reviewed Jun 1, 2026 Content v20260601
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
advanced

This lesson

This lesson teaches useMemo and useCallback: the concepts, APIs, and habits you need before advancing in React.

Hooks encode reusable stateful logic; senior reviews focus on whether you reached for the right hook.

You will apply useMemo and useCallback in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When hooks, state, and effects from intermediate lessons are familiar.

useMemo caches a computed value; useCallback caches a function reference. Both help when expensive work or referential equality matters—typically with React.memo children or stable effect dependencies.

useMemo

const sorted = React.useMemo(() => heavySort(items), [items]);

Recomputes only when items changes. Do not wrap every arithmetic operation—profile first.

useCallback

const onSave = React.useCallback(() => save(draft), [draft]);

Returns the same function identity until draft changes—stops child memo components from rerendering because a new inline function appeared.

When NOT to optimize

  • Lists under ~100 items with cheap renders
  • Components not wrapped in memo
  • Premature optimization before measuring

Interview note

React 19+ compiler efforts may auto-memoize in some setups; still know manual hooks for interviews and legacy codebases.

Self-check

  1. What problem does useCallback solve for child components?
  2. Why is an empty dependency array dangerous for callbacks that close over props?

Tip: Measure before memoizing—useMemo has its own cost and hurts readability when overused.

Interview prep

When do useMemo and useCallback help?

When expensive work or stable function references prevent unnecessary child re-renders—profile first; premature memoization adds complexity.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Premature memo risk?
  • When memo helped?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump