Updating the array object in React state using immutability helper

后端 未结 2 632
渐次进展
渐次进展 2020-12-25 14:11

I am updating an object within an array in React state using immutability helper.

The object I want to modify is nested:



        
2条回答
  •  情歌与酒
    2020-12-25 14:29

    One way to do it would be using $set

    let index = 0;
    let newState = update(this.state, {
       a: {
         b: {
          [index]: {
                   c: { $set: "new value"}
           }
        }
      }
    });
    this.setState(newState);
    

    jsfiddle

提交回复
热议问题