Skip to content
Advertisement

Changing the values of objects in an array with React

While working on React today, I got stuck somewhere because my basic JavaScript knowledge is not good.

I want to change the value of the “name” property of any object in this array.

Codesandbox: https://codesandbox.io/s/dank-rain-udjcxe?file=/src/App.js

JavaScript

My App.js file

JavaScript

Advertisement

Answer

Essentially you need to create an updated array and set it. Use the callback method setPeople to update the array. Try like this:

JavaScript
JavaScript
Advertisement