From 6926de1108b1a084e133d5f8363f080d7c20a99f Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Fri, 9 Feb 2018 17:04:12 +0100 Subject: Use classes instead of stateless functions for Components --- .../components/presentational/IconFromUserType.js | 52 +++++++++++----------- .../react/components/presentational/Loading.js | 6 ++- .../react/components/presentational/Result.js | 42 +++++++++-------- .../react/components/presentational/Schedule.js | 8 ++-- 4 files changed, 59 insertions(+), 49 deletions(-) (limited to 'src/client/react/components/presentational') diff --git a/src/client/react/components/presentational/IconFromUserType.js b/src/client/react/components/presentational/IconFromUserType.js index ee0e04b..2ef95b7 100644 --- a/src/client/react/components/presentational/IconFromUserType.js +++ b/src/client/react/components/presentational/IconFromUserType.js @@ -5,33 +5,35 @@ import RoomIcon from 'react-icons/lib/md/room'; import ClassIcon from 'react-icons/lib/md/group'; import TeacherIcon from 'react-icons/lib/md/account-circle'; -const IconFromUserType = ({ userType, defaultIcon }) => { - switch (userType) { - case 'c': - return ; - case 't': - return ; - case 's': - return ; - case 'r': - return ; - default: - if (defaultIcon) { - return defaultIcon; - } +class IconFromUserType extends React.Component { + static propTypes = { + userType: PropTypes.string, + defaultIcon: PropTypes.element, + }; - throw new Error('`userType` was invalid or not given, but `defaultIcon` is not defined.'); - } -}; + static defaultProps = { + userType: null, + defaultIcon: null, + }; -IconFromUserType.propTypes = { - userType: PropTypes.string, - defaultIcon: PropTypes.element, -}; + render() { + switch (this.props.userType) { + case 'c': + return ; + case 't': + return ; + case 's': + return ; + case 'r': + return ; + default: + if (this.props.defaultIcon) { + return this.props.defaultIcon; + } -IconFromUserType.defaultProps = { - userType: null, - defaultIcon: null, -}; + throw new Error('`userType` was invalid or not given, but `defaultIcon` is not defined.'); + } + } +} export default IconFromUserType; diff --git a/src/client/react/components/presentational/Loading.js b/src/client/react/components/presentational/Loading.js index 84eaac7..2ab80da 100644 --- a/src/client/react/components/presentational/Loading.js +++ b/src/client/react/components/presentational/Loading.js @@ -1,5 +1,9 @@ import React from 'react'; -const Loading = () =>
Loading...
; +class Loading extends React.Component { + render() { + return
Loading...
; + } +} export default Loading; diff --git a/src/client/react/components/presentational/Result.js b/src/client/react/components/presentational/Result.js index 6d39a80..a30cf52 100644 --- a/src/client/react/components/presentational/Result.js +++ b/src/client/react/components/presentational/Result.js @@ -5,25 +5,29 @@ import users from '../../users'; import IconFromUserType from './IconFromUserType'; -const Result = ({ userId, isSelected, onClick }) => ( - // eslint-disable-next-line -
-
- -
-
{users.byId[userId].value}
-
-); +class Result extends React.Component { + static propTypes = { + userId: PropTypes.string.isRequired, + isSelected: PropTypes.bool.isRequired, + onClick: PropTypes.func.isRequired, + }; -Result.propTypes = { - userId: PropTypes.string.isRequired, - isSelected: PropTypes.bool.isRequired, - onClick: PropTypes.func.isRequired, -}; + render() { + return ( + // eslint-disable-next-line +
+
+ +
+
{users.byId[this.props.userId].value}
+
+ ); + } +} export default Result; diff --git a/src/client/react/components/presentational/Schedule.js b/src/client/react/components/presentational/Schedule.js index 3f17adc..85cf72f 100644 --- a/src/client/react/components/presentational/Schedule.js +++ b/src/client/react/components/presentational/Schedule.js @@ -3,6 +3,10 @@ import PropTypes from 'prop-types'; import createDOMPurify from 'dompurify'; class Schedule extends React.Component { + static propTypes = { + htmlStr: PropTypes.string.isRequired, + }; + constructor(props) { super(props); @@ -58,8 +62,4 @@ class Schedule extends React.Component { } } -Schedule.propTypes = { - htmlStr: PropTypes.string.isRequired, -}; - export default Schedule; -- cgit v1.1