Quantcast
Channel: What is mapDispatchToProps? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by hamstu for What is mapDispatchToProps?

$
0
0

It's basically a shorthand. So instead of having to write:

this.props.dispatch(toggleTodo(id));

You would use mapDispatchToProps as shown in your example code, and then elsewhere write:

this.props.onTodoClick(id);

or more likely in this case, you'd have that as the event handler:

<MyComponent onClick={this.props.onTodoClick} />

There's a helpful video by Dan Abramov on this here: https://egghead.io/lessons/javascript-redux-generating-containers-with-connect-from-react-redux-visibletodolist


Viewing all articles
Browse latest Browse all 7

Trending Articles