diegoddox / react-redux-toastr

react-redux-toastr is a toastr message implemented with Redux
http://diegoddox.github.io/react-redux-toastr/
MIT License
752 stars 149 forks source link

TypeError: state.get is not a function #106

Closed jkurei closed 7 years ago

jkurei commented 7 years ago

I'm trying to use this module and I've run against a few issues. The first one was this error:

ReduxToastr.js:159 Uncaught TypeError: state.get is not a function
    at eval (ReduxToastr.js:159)
    at Connect.configureFinalMapState (connect.js:155)
    at Connect.computeStateProps (connect.js:142)
    at Connect.updateStatePropsIfNeeded (connect.js:204)
    at Connect.render (connect.js:340)
    at eval (ReactCompositeComponent.js:796)
    at measureLifeCyclePerf (ReactCompositeComponent.js:75)
    at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:795)
    at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:822)
    at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:362)

Located in this line, in node_modules/react-redux-toastr/lib/ReduxToastr.js:

exports.default = (0, _reactRedux.connect)(function (state) {
  return {
    toastr: state.toastr ? state.toastr : state.get('toastr')
  };
}, actions)(ReduxToastr);

I'm by no means a redux expert, but the only situation I know where state has a get method is using libraries redux-immutablejs. I don't think react-redux-toastr should assume the user is using immutable, if that's the case.

diegoddox commented 7 years ago

Hi, that is the case, we check to se if we have a toastr fi we don't have that means is a immutablejs object. Here is the code

diegoddox commented 7 years ago

I will close but feel free to re-open in case you need but the only way I think you can get this error is if you don't have setup the reducer in the proper way

patvdleer commented 7 years ago

This may help others.

change const rootReducer = combineReducers({ routing: routerReducer, toastrReducer, });

to: const rootReducer = combineReducers({ routing: routerReducer, toastr: toastrReducer, });

atlanteh commented 6 years ago

for me the issue was I did: combineReducers({..., toaster: toastrReducer, }); toaster instead of toastr 😆