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