Module 3 of 7

Advanced React APIs

These are the APIs you don't reach for every day. Each one exists because React's default model sometimes isn't enough:

The examples are all part of the product store: a cart reducer, a theme and cart context, a "Quick view" dialog, a shipping tooltip, a coupon field, a wishlist, and a cart store shared by two React roots. Every log, render list and painted frame was recorded by running the store in Chrome (examples/product-store/src/lessons/apis).

Reaching for one of these is a sign you've hit a real boundary. Two of them pair up: useLayoutEffect reads the DOM before paint, and flushSync writes it before your next line of code.

Start with “useReducer”All notesInterview questions

The notes

Read them in order. Each one builds on the ones before it.

01Must know

useReducer

A cart as one pure reducer with typed actions: dispatch, lazy init, testing without React, and when React bails out.

Read
02Must know

Context with use

createContext, a provider and use(): skip the prop drilling, and know exactly which components re-render.

Read
03Must know

createPortal

Render a dialog into document.body so a clipping parent can’t hide it; events and context still follow the React tree.

Read
04Good to know

useLayoutEffect

Measure before the browser paints: the recorded frame where a useEffect tooltip covers its button.

Read
05Good to know

useImperativeHandle

Expose a small set of methods (focus, clear) on a ref, for commands that don’t fit in state.

Read
06Good to know

flushSync

Make React update the DOM before the next line runs, so you can focus or scroll to what you just rendered.

Read
07Good to know

useSyncExternalStore

Read state React doesn’t own (the browser, a plain JS store) safely, with stable snapshots and a server value.

Read