Preventing extra renders with React.memo
In the previous lesson, you split State and Dispatch into separate contexts to stop “write-only” components from re-rendering on every tick. In this lesson, you will push that idea into the UI. We will use React.memo to keep static UI pieces from re-rendering when their inputs have not changed. Our focus is the GameActions UI: you will memoize the ActionButton leaf component and also the container itself so parent updates do not cascade.
Memoizing the leaf: ActionButton
What it does:
- Wraps the button card in
React.memoso React can skip re-rendering when its props are the same (shallow compare). - Receives three inputs: the
actiondescriptor, theonClickhandler, and thedisabledflag. - Blurs the button after a click for a cleaner keyboard/focus experience.
- This concentrates re-rendering on the specific buttons whose inputs actually change.
Passing the right props to each memoized button
What it does:
- Renders a grid of
ActionButtoncomponents, one peractiondescriptor. onClicktriggers the proper game action (only when enabled).disabledalso honors the global pause state to prevent accidental input during a pause.- Because each
ActionButtongets only the data it needs,React.memocan compare those props and avoid re-rendering buttons whose inputs did not change.
Memoizing the container
What it does:
- Wraps the
GameActionscontainer inReact.memoso it will not re-render due to parent updates unless its own props change. - Combined with the separate
Dispatchcontext (from the previous lesson), this helps isolate the action panel so the frequent timer tick does not ripple through components that do not need to change.
Summary and what’s next
You learned how to:
- Use
React.memoto keep leaf UI (ActionButton) from re-rendering when props are unchanged. - Pass focused props (
action,onClick,disabled) so only the affected buttons update. - Memoize the container to block parent-driven re-renders.
Up next, you will put these ideas into action and see how much smoother the game feels when only the right components re-render.

Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal