I am trying to update the user
object’s blockedUsers
array, while keeping other data not changed. user
object can have blockedUsers
array or not, it is not certain. In slice I have:
reducers: { CHANGE_USER: (state, action) => {
state.user.push(action.payload)
},
}
And in component, I am trying to update this way:
dispatch(CHANGE_USER({blockedUsers: [...user?.blockedUsers, selectedUser] }))
where selectedUser is an object: {id: "xxxx", name: "yyyy"}
. But error comes:
Possible unhandled promise rejection (id:2).
TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator()] method.
How can I solve this?