React - a price-sorted product list
function ProductList({ items }: { items: Product[] }) {
const sorted = useMemo(
() => items.sort((a, b) => a.price - b.price),
[items],
);
return <ul>{sorted.map(renderRow)}</ul>;
}
() => [...items].sort((a, b) => a.price - b.price),What breaks: sort() orders in place, so this reorders the caller's array as a side effect of rendering. Every other component holding that prop silently changes order too.

