dispatch is not a function React redux

敲代码遇到如下问题:
dispatch is not a function React redux_第1张图片
组件内原代码

const mapDispatchToProps = (dispatch) => {
  return bindActionCreators(actionCreators,dispatch)
}

修改后:

const mapDispatchToProps = (dispatch) => {
    return {
        dispatch: dispatch,
        ...bindActionCreators(actionCreators,dispatch)
    }
}

这样就可以解决。
暴露的组件记得用connect包起来

export default connect(mapStateToProps,mapDispatchToProps)(Head)

你可能感兴趣的:(React)