this.props.dispatch不是一个函数

Muh*_*zam 3 reactjs redux react-redux

我尝试使用时无法调用调度功能 bindActionCreators

调度功能不起作用:

@connect(state => ({oPurchaseDetails: state.cart.cartItems}), dispatch => bindActionCreators({updateItem}, dispatch))
Run Code Online (Sandbox Code Playgroud)

如果我不使用bindActionCreators,updateItem函数不起作用.

updateItem函数不起作用:

@connect(state => ({oPurchaseDetails: state.cart.cartItems}), dispatch => ({updateItem, dispatch}))
Run Code Online (Sandbox Code Playgroud)

mar*_*son 5

connectthis.props.dispatch在您提供mapDispatch功能时自动插入.因为您使用自己的mapDispatch,所以您有责任将其包含在返回值中.

有关详细信息,请参阅http://redux.js.org/docs/faq/ReactRedux.html#react-props-dispatch.