Skip to content

Replace mapDispatchToProps object with a function #1

@ndkv

Description

@ndkv

First of all, thank you very very much for this great tutorial. It is much, much more clear than the redux and react-redux tutorials/documentations combined!

I have a small suggestion: replace { getData } on line 33 of Posts.js with a mapDispatchToProps function that extends the mapDispatchToProps function used up to this point in the tutorial as follows

function mapDispatchToProps(dispatch) {
  return {
    addArticle: article => dispatch(addArticle(article))
    getData: () => dispatch(getData())
  };
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Post);

I'm suggesting this change since it took me a while to figure out why this.props.getData() on line 11 works without a call to dispatch. It is only after I looked at the connect docs that I learned that passing an object instead of a function to connect binds dispatch to each action creator.

Don' get me wrong: it's useful to know about the Object Shorthand Form. It's just that it's a bit much when learning the basics. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions