mapDispatchToProps with bindActionCreators
parent
3137dce047
commit
a90bf1c3f3
|
@ -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)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue