cf.completefrontend

ConceptMedium

When does memo help, and why do inline objects and functions break it?

The code
const TeaList = memo(function TeaList({ teas, options, onAdd }) {
  // slow: renders hundreds of rows
});
 
function Shop({ teas }) {
  const [note, setNote] = useState("");
  return (
    <>
      <input value={note} onChange={(e) => setNote(e.target.value)} />
      <TeaList teas={teas} options={{ inStock: true }} onAdd={(tea) => addToCart(tea)} />
    </>
  );
}

Practice it in the editor, with tests

The answer

Answer it out loud first, the way you would in the interview. Then compare.

Checking your sign-in…