1function memoRender(name, props, last) {
2 const same = last && Object.keys(props).every((k) => props[k] === last[k]);
3 console.log(name + ":", same ? "SKIPPED (props identical)" : "re-rendered");
4 return props;
5}
6const user = { name: "Ravi" };
7let a = null, b = null;
8a = memoRender("BadgeA", { user: user }, a);
9a = memoRender("BadgeA", { user: user }, a);
10b = memoRender("BadgeB", { user: { name: "Ravi" } }, b);
11b = memoRender("BadgeB", { user: { name: "Ravi" } }, b);
●You wrapped a slow component in React.memo… and it still re-renders every time. The most common "memo does nothing" complaint has a five-character cause: the === it uses.
We implement memo’s actual comparison in three lines, then feed it the same props two different ways — one skips, one never can.
📦 Memory boxes
what the program is remembering right now
nothing remembered yet🖥️ What the computer shows
the answers the program prints out
nothing yet ▌