Command Palette

Search for a command to run...

Hectal
Phase 4: State and Events
React · Exercise 3 of 5 PreviousNext
Beginner

Edit a nested object without mutating

The profile state is { name: "Asha", address: { city: "Pune", pin: "411001" } }. The paragraph id="summary" shows Asha lives in Pune (411001).

Make the button id="move" change the city to Mumbai and the pin to 400001, and the button id="rename" change the name to Ravi. The starter mutates the object, so nothing updates. Create new objects instead.

What Check tests

  1. It starts as Asha lives in Pune (411001)
  2. Move shows Asha lives in Mumbai (400001)
  3. Rename then shows Ravi lives in Mumbai (400001)
  4. The code no longer assigns to fields of person

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.