Skip to content

Commit

Permalink
Clarify two way dispatch binding in more detail (#1387)
Browse files Browse the repository at this point in the history
* Clarify two way dispatch binding in more detail

* Formatted the new code blocks
  • Loading branch information
aminsoheyli authored and timdorr committed Aug 27, 2019
1 parent e228b32 commit 5b268f3
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -151,11 +151,25 @@ If your `mapDispatchToProps` function is declared as taking two parameters, it w

This means, instead of re-binding new `props` to action dispatchers upon component re-rendering, you may do so when your component's `props` change.

**Binds on component re-rendering**

```js
render() {
return <button onClick={() => this.props.toggleTodo(this.props.todoId)} />
}

const mapDispatchToProps = dispatch => {
toggleTodo: todoId => dispatch(toggleTodo(todoId))
}
```

**Binds on `props` change**

```js
// binds on component re-rendering
;<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
render() {
return <button onClick={() => this.props.toggleTodo()} />
}

// binds on `props` change
const mapDispatchToProps = (dispatch, ownProps) => {
toggleTodo: () => dispatch(toggleTodo(ownProps.todoId))
}
Expand Down

0 comments on commit 5b268f3

Please sign in to comment.