How to update object in React state

后端 未结 5 1355
野的像风
野的像风 2021-02-18 22:30

I have an indexed list of users in the JS object (not array). It\'s part of the React state.

{
    1: { id: 1, name: \"John\" }
    2: { id: 2, name         


        
5条回答
  •  盖世英雄少女心
    2021-02-18 23:21

    Apart from _.extend you can use Map for storing user

    let user = new Map();
    user.set(4, { id: 4, name: "Jane" }); //adds with id (4) as key
    user.myMap.set(2, { id: 2, name: "Peter" }); // set user #2 to "Peter"
    user.delete(3); //deletes user with id 3
    

提交回复
热议问题