WeCodeAcademy

Updating Objects and Arrays in State

State must be treated as read only. To change an object or array, build a new copy with spread syntax.

Examplereact
Open in editor »

{ ...user, age: 37 } copies user and replaces age. If you instead did user.age++, React would not notice the change.

Quick check

How do you add an item to an array held in state?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.