Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

TypeError: Cannot read property 'type' of undefined #493

Closed
ideal-life-generator opened this issue Dec 11, 2016 · 4 comments
Closed

TypeError: Cannot read property 'type' of undefined #493

ideal-life-generator opened this issue Dec 11, 2016 · 4 comments

Comments

@ideal-life-generator
Copy link

ideal-life-generator commented Dec 11, 2016

When I use more flexible middlewares, like redux-thunk, I can return undefined in end of action. Then I have routerMiddleware error in:

if (action.type !== _actions.CALL_HISTORY_METHOD) {
TypeError: Cannot read property 'type' of undefined

I think you need ignoring undefined or different not standard actions returning. Here is example of action:

export function checkStoredUser() {
  const refreshToken = cookie.load('refresh-token');
  const token = cookie.load('token');

  if (token || refreshToken) {
    setDefaultHeader('Authorization', token);

    return async (dispatch) => {
      dispatch(setStored());

      await dispatch(me());
    };
  }

  return undefined;
}

I think is normal for redux, because I don't have the same problems with other soft.

if (action && action.type === _actions.CALL_HISTORY_METHOD) {
...
} else {
  next(action);
}
@timdorr
Copy link
Member

timdorr commented Dec 11, 2016

You just have to order your middleware correctly. Make sure redux-thunk is first.

@timdorr timdorr closed this as completed Dec 11, 2016
@ideal-life-generator
Copy link
Author

ideal-life-generator commented Dec 13, 2016

If I don't use redux-thunk is also throw this error. It has wrong architecture.

@timdorr
Copy link
Member

timdorr commented Dec 13, 2016

You are doing something wrong if you're passing in an action that is not an object with a type field, and you don't have a middleware set up to handle that. We expect a type field, the same as redux does: https://github.com/reactjs/redux/blob/master/src/createStore.js#L157-L162

@ideal-life-generator
Copy link
Author

ideal-life-generator commented Dec 13, 2016

I'm sorry, you right) Without additional middleware is no have sense anything.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants