I have my reducer where I am using Immutable and I need to update my state based on the data received from my API. The data received is an object. So every time I receive the data, I need to push that object in an array i.e. create an array of objects. Facing an issue here. Following is my code in my reducer:
import { Map, fromJS } from 'immutable';
import actionTypes from '../actions/actionTypes';
const initialState = Map({
weather: [],
fetchWeatherError: ''
});
export default function appReducer(state = initialState, action) {
switch (action.type) {
case actionTypes.FETCH_WEATHER_SUCCESS: {
console.log("ation", action.data);
return state.set('weather', action.data)
.set('fetchWeatherError', '')
}
case actionTypes.FETCH_WEATHER_ERROR: {
return state.set('fetchWeatherError', action.error)
.set('weather', null)
}
default:
return state;
}
}
The line return state.set('weather', action.data) instead of updating my state I need to push the new data every time in the weather array. Please let me know if any inputs on the same, as this is just updating my state and not giving me an array.