Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immer does not support setting non-numeric properties on arrays

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?

like image 981
Daniel Reina Avatar asked Dec 06 '25 04:12

Daniel Reina


1 Answers

This happens when you pass something not an object for state. Make sure state is an object.

like image 85
Dani Vijay Avatar answered Dec 08 '25 18:12

Dani Vijay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!