mapDispatchToProps

master
Tudor Stanciu 2020-04-11 19:32:20 +03:00
parent 0fa1f83aa9
commit 3137dce047
1 changed files with 9 additions and 3 deletions

View File

@ -17,7 +17,7 @@ class CoursesPage extends React.Component {
handleSubmit = (event) => { handleSubmit = (event) => {
event.preventDefault(); event.preventDefault();
this.props.dispatch(courseActions.createCourse(this.state.course)); this.props.createCourse(this.state.course);
}; };
render() { render() {
@ -40,7 +40,7 @@ class CoursesPage extends React.Component {
} }
CoursesPage.propTypes = { CoursesPage.propTypes = {
dispatch: PropTypes.func.isRequired, createCourse: PropTypes.func.isRequired,
courses: PropTypes.array.isRequired courses: PropTypes.array.isRequired
}; };
@ -50,4 +50,10 @@ function mapStateToProps(state) {
}; };
} }
export default connect(mapStateToProps)(CoursesPage); function mapDispatchToProps(dispatch) {
return {
createCourse: (course) => dispatch(courseActions.createCourse(course))
};
}
export default connect(mapStateToProps, mapDispatchToProps)(CoursesPage);