Lesson 18 — useMemo
Skip work that has not changed
Every re-render runs your whole component again, including slow calculations. useMemo(() => calc(), [deps]) remembers (memoizes) the result and only recalculates when something in the dependency array changes. Other state changes reuse the saved value.
const sorted = useMemo(() => [...rows].sort(byName), [rows]);
Why it matters: it keeps typing and clicking smooth when a page filters or sorts big lists.
Wrap the sum in useMemo with [nums]. Clicking Theme should no longer increase "Sum runs" — only Add number should.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based React Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for React Foundations books — check the publication year so the examples match current versions.
Search Amazon →