Skip to content

Commit def86ae

Browse files
committed
Use mapDispatchToProps to bind actions efficiently
1 parent e6715a1 commit def86ae

File tree

1 file changed

+12
-5
lines changed
  • examples/todomvc/containers

1 file changed

+12
-5
lines changed

examples/todomvc/containers/App.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import * as TodoActions from '../actions/todos';
77

88
class App extends Component {
99
render() {
10-
const { todos, dispatch } = this.props;
11-
const actions = bindActionCreators(TodoActions, dispatch);
12-
10+
const { todos, actions } = this.props;
1311
return (
1412
<div>
1513
<Header addTodo={actions.addTodo} />
@@ -21,7 +19,7 @@ class App extends Component {
2119

2220
App.propTypes = {
2321
todos: PropTypes.array.isRequired,
24-
dispatch: PropTypes.func.isRequired
22+
actions: PropTypes.object.isRequired
2523
};
2624

2725
function mapStateToProps(state) {
@@ -30,4 +28,13 @@ function mapStateToProps(state) {
3028
};
3129
}
3230

33-
export default connect(mapStateToProps)(App);
31+
function mapDispatchToProps(dispatch) {
32+
return {
33+
actions: bindActionCreators(TodoActions, dispatch)
34+
};
35+
}
36+
37+
export default connect(
38+
mapStateToProps,
39+
mapDispatchToProps
40+
)(App);

0 commit comments

Comments
 (0)