convert ManageCoursePage from class to function with hooks

master
Tudor Stanciu 2020-04-11 23:35:57 +03:00
parent 3a6fcd1637
commit 2fe0b6c647
1 changed files with 9 additions and 13 deletions

View File

@ -1,14 +1,12 @@
import React from "react"; import React, { useEffect } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { loadCourses } from "../../redux/actions/courseActions"; import { loadCourses } from "../../redux/actions/courseActions";
import { loadAuthors } from "../../redux/actions/authorActions"; import { loadAuthors } from "../../redux/actions/authorActions";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { bindActionCreators } from "redux"; import { bindActionCreators } from "redux";
class ManageCoursePage extends React.Component { function ManageCoursePage({ courses, authors, actions }) {
componentDidMount() { useEffect(() => {
const { courses, authors, actions } = this.props;
if (courses.length === 0) { if (courses.length === 0) {
actions.loadCourses().catch((error) => { actions.loadCourses().catch((error) => {
alert("Loading courses failed. " + error); alert("Loading courses failed. " + error);
@ -20,15 +18,13 @@ class ManageCoursePage extends React.Component {
alert("Loading authors failed. " + error); alert("Loading authors failed. " + error);
}); });
} }
} }, []);
render() {
return ( return (
<> <>
<h2>Manage course</h2> <h2>Manage course</h2>
</> </>
); );
}
} }
ManageCoursePage.propTypes = { ManageCoursePage.propTypes = {