Simulate React reconciliation: 5 levels placing memo, useMemo, useCallback and split contexts. Watch real render waves and optimize until you meet the budget.
What the levels ask
A setState in App sends a render wave through its whole subtree. Watch how many times each component renders, and meet its budget.
Counter shows a count that changes often. Sidebar takes no props at all, yet it renders every time. Use React.memo to skip it. A switch is not free: every time its parent renders it checks the props, and that check counts against its house's allowance.
UserCard is memoized, but every App render creates a new user={...} literal: the shield leaks. Stabilize the reference.
Button (the Clear button) is memoized, but Form passes onClick={() => setValue('')} inline. Every render, a new function.
AppProvider broadcasts {user, theme}: every consumer renders even though only user changed. Split the context.
App keeps derived values in state (total, then average) and copies them with useEffect whenever its data changes. One change becomes three render waves. Watch the cascade, then see why computing them directly is better.
App uses a ref countRef to keep a count (not state). Every click increments countRef.current. Mutating a ref does NOT trigger a render.
Two children need the same state (the cart). The state has to be lifted to App, their common ancestor. As a result a setState in App sends a wave through the whole subtree. Add a memo to limit its reach.
The search state lives in SearchBox, so every keystroke only wakes SearchBox and Input. Someone suggests lifting it to App so ResultList could read it some day. Count first: is it needed, for these keystrokes?
The list uses key={index}. When a new item is put at the front, React matches by position, not identity: every item re-renders with shifted data, and its state stays behind at its position. Watch the wave.
StrictMode wraps App. In development every render runs TWICE to catch side effects in render. One setState, two renders.
The search box keeps keystrokes in query; the 10k-item list is only filtered on Enter (search). Yet every letter still re-renders every Row. BigList is already memoized: stabilize its filter data so the wave does not reach the 10k Rows on every keystroke.