Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace mapDispatchToProps object with a function #1

Open
ndkv opened this issue Nov 28, 2019 · 0 comments
Open

Replace mapDispatchToProps object with a function #1

ndkv opened this issue Nov 28, 2019 · 0 comments

Comments

@ndkv
Copy link

ndkv commented Nov 28, 2019

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant