state.get is not a function when trying to map the react-redux State

Viewed 5203

Here I am trying to display the sources in my component but always i find error as state.get is not a function.

reducer.js

let initialState = Immutable.fromJS({sources: []});

export default function (state = initialState, action){
     switch(action.type){
         case GetSources:
             return state.merge({
                sources: action.sources
             });
        break;
     }
     return state;
}

Component.js

function mapStateToProps(state){
     return{
         sources: state.get('sources')
     }
}

allReducers.js

`const allReducers = combineReducers({
    sources:sources,
    news:news
})`
2 Answers

In my case, it is because of the state persist in the local app state in chrome, and after I clean data site, it works. I guess it is because of the state in my local is regular JS object and it needs to be removed first. otherwise it will convert the state back to regular JS object, even you combine it as immutable.

Related