From 2fe0b6c647c087a9e1b8a91798e8a5dc3c55179d Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 11 Apr 2020 23:35:57 +0300 Subject: [PATCH] convert ManageCoursePage from class to function with hooks --- src/components/courses/ManageCoursePage.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/components/courses/ManageCoursePage.js b/src/components/courses/ManageCoursePage.js index a0c591a..e7387ca 100644 --- a/src/components/courses/ManageCoursePage.js +++ b/src/components/courses/ManageCoursePage.js @@ -1,14 +1,12 @@ -import React from "react"; +import React, { useEffect } from "react"; import { connect } from "react-redux"; import { loadCourses } from "../../redux/actions/courseActions"; import { loadAuthors } from "../../redux/actions/authorActions"; import PropTypes from "prop-types"; import { bindActionCreators } from "redux"; -class ManageCoursePage extends React.Component { - componentDidMount() { - const { courses, authors, actions } = this.props; - +function ManageCoursePage({ courses, authors, actions }) { + useEffect(() => { if (courses.length === 0) { actions.loadCourses().catch((error) => { alert("Loading courses failed. " + error); @@ -20,15 +18,13 @@ class ManageCoursePage extends React.Component { alert("Loading authors failed. " + error); }); } - } + }, []); - render() { - return ( - <> -

Manage course

- - ); - } + return ( + <> +

Manage course

+ + ); } ManageCoursePage.propTypes = {