What types of things would cause Immer only supports setting array indices and the 'length' property' from the code below? This FoodLogState type is a class. I've done something very similar with no issue. I notice I am not updating even the array from state yet. Only the status that is a string.
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { FoodLogState, getFoodState } from "../AccountAPI";
export interface FoodLogs {
foodLogs: Array<FoodLogState>;
status: "idle" | "loading" | "failed";
}
const initialState: FoodLogs = {
foodLogs: null,
status: "idle",
};
export const getFoodLogsAsync = createAsyncThunk(
"foodsLogged/getFoodsLogged",
async (uid: string, { rejectWithValue }) => {
try {
const response = await getFoodState(uid).catch((error) => {
return rejectWithValue(error.message);
});
return response;
} catch (error) {
return rejectWithValue(error.message);
}
}
);
const foodsLogSlice = createSlice({
name: "foodsLogged",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(getFoodLogsAsync.fulfilled, (state, action) => {
//state.foodLogs = action.payload;
state.status = "idle";
})
.addCase(getFoodLogsAsync.rejected, (state, action) => {
state.status = "failed";
})
.addCase(getFoodLogsAsync.pending, (state) => {
state.status = "loading";
});
},
});
export const selectFoods = (state) => state.foodLog;
export default foodsLogSlice.reducer;