State

Nested state copying

Copy the changed nested record and its ancestor containers; keep unchanged branches shared.

Formal Syntax & Structure

react syntaxreact
{ ...old, nested: { ...old.nested, field: value } }

Working Example

Example Snippetreact
const next = { ...order, address: { ...order.address, city: "Bergen" } };
React Reference