From 2061371670eabb825081c76b32ef006f493112b6 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 11 Apr 2020 16:42:26 +0300 Subject: [PATCH] connect component to redux --- src/components/courses/CoursesPage.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/courses/CoursesPage.js b/src/components/courses/CoursesPage.js index 66b09ce..86735d8 100644 --- a/src/components/courses/CoursesPage.js +++ b/src/components/courses/CoursesPage.js @@ -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);