I have a immutable state in reducer as:
const initialState = fromJS({
rates: [],
fromDialogOpen: false,
mealPlans: [],
roomTypes: [],
editRateFormOpen: false,
rateToEdit: "",
selectedDate: moment().toDate(),
selectedRoomType: null,
selectedMealPlan: null
});
I do an api call that results me either an empty array [] or array of objects
[
0: Object { doubleRackRate: 200, singleRackRate: 120, mealPlan: "AI", … }
1: Object { doubleRackRate: 12, singleRackRate: 1200, mealPlan: "AI", … }
2: Object { doubleRackRate: 12, singleRackRate: 12, mealPlan: "AI", … }
3: Object { doubleRackRate: 12, singleRackRate: 12, mealPlan: "AI", … }
4: Object { doubleRackRate: 12, singleRackRate: 12, mealPlan: "AI", … }
]
sent as action.payload for state update!
As I receive the array from API call I need to update my rates- state to the value I receive - i.e. either an empty array or the array of objects !!
How can I do this? I tried:
return Object.assign( ...state, {rates:action.payload})
But this didn't work !!