connect component to redux

master
Tudor Stanciu 2020-04-11 16:42:26 +03:00
parent f539da1f77
commit 2061371670
1 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,7 @@
import React from "react";
import { connect } from "react-redux";
import * as courseActions from "../../redux/actions/courseActions";
import PropTypes from "prop-types";
class CoursesPage extends React.Component {
state = {
@ -14,7 +17,7 @@ class CoursesPage extends React.Component {
handleSubmit = (event) => {
event.preventDefault();
alert(this.state.course.title);
this.props.dispatch(courseActions.createCourse(this.state.course));
};
render() {
@ -33,4 +36,14 @@ class CoursesPage extends React.Component {
}
}
export default CoursesPage;
CoursesPage.propTypes = {
dispatch: PropTypes.func.isRequired
};
function mapStateToProps(state) {
return {
courses: state.courses
};
}
export default connect(mapStateToProps)(CoursesPage);