I have an indexed list of users in the JS object (not array). It\'s part of the React state.
users
{ 1: { id: 1, name: \"John\" } 2: { id: 2, name
Using spreads:
Adding
this.setState({ ...this.state, 4: { id: 4, name: "Jane" }, }
Removing id 2
let prevState = this.state; let {"2": id, ...nextState} = prevState; this.setState({ ...nextState, }
Changing id 2
this.setState({ ...this.state, 2: { ...this.state["2"], name: "Peter", } }