I’m trying to update my slice state. I’m using redux-toolkit.
And my slice state and update reducer are like this:
// state
const initialState = {
bet: {
betItems: [{id : 0}]
}
}
// reducer
updateBetItems: (state, action) => {
state.bet.betItems = action.payload
},
When the action.payload is an empty array ([]), updateBetItems reducer shows an error like this :
TypeError: Cannot assign to read only property ‘betItems’ of object ‘#’. But if the action.payload is not an empty array such as [{id: 1}, {id :2}] there were no problem.
Could you help anyone?
hsglc0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.