1handleChange: function (e) {
2 // 1. Make a shallow copy of the items
3 let items = [...this.state.items];
4 // 2. Make a shallow copy of the item you want to mutate
5 let item = {...items[1]};
6 // 3. Replace the property you're intested in
7 item.name = 'newName';
8 // 4. Put it back into our array. N.B. we *are* mutating the array here, but that's why we made a copy first
9 items[1] = item;
10 // 5. Set the state to our new copy
11 this.setState({items});
12},
13
1You have to use setState() for updating state in React
2{
3 hasBeenClicked: false,
4 currentTheme: 'blue',
5}
6
7setState({
8 hasBeenClicked: true
9});
10