错误:redux-thunk this.props.dispatch不是函数

时间:2017-10-03 18:47:20

标签: reactjs redux redux-thunk

当我点击按钮时出现错误

  

未捕获的TypeError:_this2.props.dispatch不是函数

@

请帮帮我

1 个答案:

答案 0 :(得分:1)

const mapDispatchToProps =  (dispatch) => {
    return {
        activateGeod: bindActionCreators(activateGeod, dispatch),
        closeGeod: bindActionCreators(closeGeod, dispatch),
    }
};

应该是

const mapDispatchToProps =  (dispatch) => ({
  activateGeod: bindActionCreators(activateGeod, dispatch),
  closeGeod: bindActionCreators(closeGeod, dispatch),
  logout: () => dispatch(logout()),
});

然后,您只需在组件中调用this.props.logout()而不是dispatch(logout())