Lesson 19 — useCallback
Keep the same function between renders
Each render creates brand-new functions, so a child wrapped in memo (which skips re-rendering when its props are unchanged) still re-renders — the function prop looks "new" every time. useCallback(fn, [deps]) returns the same function object until a dependency changes, so memo can do its job.
const save = useCallback(() => api.save(id), [id]);
<SaveButton onSave={save} />
Why it matters: in big lists and dashboards this stops hundreds of needless re-renders.
Wrap inc in useCallback with []. Clicking Theme should no longer increase the "+1" button's render count.
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 →