Skip to content

Commit 5b268f3

Browse files
aminsoheylitimdorr
authored andcommitted
Clarify two way dispatch binding in more detail (#1387)
* Clarify two way dispatch binding in more detail * Formatted the new code blocks
1 parent e228b32 commit 5b268f3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

docs/using-react-redux/connect-dispatching-actions-with-mapDispatchToProps.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,25 @@ If your `mapDispatchToProps` function is declared as taking two parameters, it w
151151

152152
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.
153153

154+
**Binds on component re-rendering**
155+
156+
```js
157+
render() {
158+
return <button onClick={() => this.props.toggleTodo(this.props.todoId)} />
159+
}
160+
161+
const mapDispatchToProps = dispatch => {
162+
toggleTodo: todoId => dispatch(toggleTodo(todoId))
163+
}
164+
```
165+
166+
**Binds on `props` change**
167+
154168
```js
155-
// binds on component re-rendering
156-
;<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
169+
render() {
170+
return <button onClick={() => this.props.toggleTodo()} />
171+
}
157172

158-
// binds on `props` change
159173
const mapDispatchToProps = (dispatch, ownProps) => {
160174
toggleTodo: () => dispatch(toggleTodo(ownProps.todoId))
161175
}

0 commit comments

Comments
 (0)