connect component to redux
parent
f539da1f77
commit
2061371670
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue