Advanced React: Rendering and Performance

Why components render, how React batches updates, where stale values come from, how keys decide identity, and when memo, useMemo and useCallback actually help. Every lesson runs a real React component step by step.

React · intermediate · 9 lessons · 1 h 5 min · free

What you'll learn

Before you start

Lessons

How Rendering Works

Renders, batching, stale closures, keys and derived state.

  1. When Does a Component Render?: Click once and count the renders: the parent, and every child with it. See why that is cheap, and what actually reaches the page.
  2. Batching: Many Updates, One Render: Three setters in one click lead to one render, not three. Watch the queue fill up and empty in a single pass.
  3. Stale Closures: Click twice, and two timers add one each. Why does the count only reach 1? Each timer remembers the count from its own render.
  4. Keys and Component Identity: Type a message to Ada, then switch to Linus. A key makes React start a fresh Chat so the draft is not sent to the wrong person.
  5. Derived State: Calculate, Don't Store: Filter a list from the search text on every render instead of keeping a second copy in state.

Performance

Skipping work with memo, useMemo and useCallback.

  1. memo: Skipping a Re-render: Wrap a component in memo and React skips it when its props have not changed. Compare it with an ordinary child.
  2. useMemo: Caching a Calculation: Keep a slow calculation from running on every render. Toggle the theme and it is skipped; change n and it runs.
  3. useCallback with memo: Give a memo child the same function every render with useCallback, and typing no longer re-renders the Save button.

App State

A reducer and context as a small app-wide store.

  1. Reducer + Context: an App Store: Keep app state in a reducer at the top and share both the state and dispatch through context. Any component can read or update it.

Related courses