mapDispatchToProps with bindActionCreators

master
Tudor Stanciu 2020-04-11 19:37:34 +03:00
parent 3137dce047
commit a90bf1c3f3
1 changed files with 5 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import * as courseActions from "../../redux/actions/courseActions"; import * as courseActions from "../../redux/actions/courseActions";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { bindActionCreators } from "redux";
class CoursesPage extends React.Component { class CoursesPage extends React.Component {
state = { state = {
@ -17,7 +18,7 @@ class CoursesPage extends React.Component {
handleSubmit = (event) => { handleSubmit = (event) => {
event.preventDefault(); event.preventDefault();
this.props.createCourse(this.state.course); this.props.actions.createCourse(this.state.course);
}; };
render() { render() {
@ -40,8 +41,8 @@ class CoursesPage extends React.Component {
} }
CoursesPage.propTypes = { CoursesPage.propTypes = {
createCourse: PropTypes.func.isRequired, courses: PropTypes.array.isRequired,
courses: PropTypes.array.isRequired actions: PropTypes.object.isRequired
}; };
function mapStateToProps(state) { function mapStateToProps(state) {
@ -52,7 +53,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return { return {
createCourse: (course) => dispatch(courseActions.createCourse(course)) actions: bindActionCreators(courseActions, dispatch)
}; };
} }