Derived State
Compute values during render instead of storing duplicates.
Example
function Cart({ items }) {
const total = items.reduce((s, i) => s + i.price * i.qty, 0);
return <p>Total {total}</p>;
}Exercise
Compute in render.
const total = items.(fn, 0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.