When would bindActionCreators be used in react/redux?

后端 未结 10 1082
温柔的废话
温柔的废话 2020-12-07 11:04

Redux docs for bindActionCreators states that:

The only use case for bindActionCreators is when you want to pass some action cre

10条回答
  •  悲哀的现实
    2020-12-07 11:41

    More complete example, pass an object full of action creators to connect:

    import * as ProductActions from './ProductActions';
    
    // component part
    export function Product({ name, description }) {
        return 
    } // container part function mapStateToProps(state) { return {...state}; } function mapDispatchToProps(dispatch) { return bindActionCreators({ ...ProductActions, }, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(Product);

提交回复
热议问题