I'm trying to update a piece of state with an array of data that I'm getting from the server. This is my reducer:
const schoolsDataReducer = (state = { data: [] }, action) =>
produce(state, draft => {
switch (action.type) {
case SET_INITIAL__DATA:
draft.data = [...action.payload.data]
break
}
})
I get this error:
"Immer does not support setting non-numeric properties on arrays: data"
How am I supposed to store an array of objects?
Are arrays in the state considered bad practice?
Am I missing something?
This happens when you pass something not an object for state. Make sure state is an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With