What is difference between dispatch and bindActionCreators?

后端 未结 1 1301
面向向阳花
面向向阳花 2021-02-02 11:33

If we are connecting to the action by using the dispatch there are two way:-

1. this.props.dispatch(requestEmployees());

2. const m         


        
相关标签:
1条回答
  • 2021-02-02 11:47

    It's actually the same thing. The result of

    bindActionCreators({ editLabResult: requestEmployees}, dispatch);
    

    Is what you've manually created:

    requestEmployees: () => dispatch(requestEmployees())
    

    According to the redux bindActionCreators documentation:

    Turns an object whose values are action creators, into an object with the same keys, but with every action creator wrapped into a dispatch call so they may be invoked directly.

    bindActionCreators({ editLabResult: requestEmployees, anotherAction, etc... }, dispatch);
    

    Instead of using bindActionCreators, you can pass the object to the connect method, and it will do the wrapping for you:

    connect(mapStateToProps, { editLabResult: requestEmployees, anotherAction, etc... })
    
    0 讨论(0)
提交回复
热议问题