From b2b71f3883b94b442f54629e209467ce410e6b08 Mon Sep 17 00:00:00 2001 From: Cory Gibbons Date: Sat, 29 Sep 2018 22:52:20 -0400 Subject: [PATCH] use functional component if methods or lifecycle hooks not needed --- src/components/About.js | 75 ++++++++++++++++++++++++------------ src/components/ListHeader.js | 18 ++++----- src/components/Menu.js | 36 +++++++++-------- src/components/NowPlaying.js | 29 ++++++-------- src/containers/App.js | 24 ++++-------- 5 files changed, 95 insertions(+), 87 deletions(-) diff --git a/src/components/About.js b/src/components/About.js index 65534e1..6d5a3d9 100644 --- a/src/components/About.js +++ b/src/components/About.js @@ -1,27 +1,41 @@ import React from 'react'; import CSSTranstionGroup from 'react-addons-css-transition-group'; -class AboutModal extends React.Component { - constructor(props) { - super(props); - } - - render() { - return ( -
-
{evt.stopPropagation()}}> -

I'm using Last.fm's API to pull in my music listening history, where I've been tracking song plays since October 2007.

-

If any of the totals are looking weird, it's because Last.fm's API is occasionally a piece of crap.

-

Really though, the site is an opportunity for me to experiment and learn more about React and especially Redux. It was developed and compiled with webpack, and styled with help from cssnext and Lost.

-

- A smahr.net project / Github -

-
-
Close
-
- ); - } -} +const AboutModal = ({ onBgClick }) => ( +
+
{ + evt.stopPropagation(); + }} + > +

+ I'm using Last.fm + 's API to pull in my music listening history, where I've been tracking + song plays since October 2007. +

+

+ If any of the totals are looking weird, it's because Last.fm's API is + occasionally a piece of crap. +

+

+ Really though, the site is an opportunity for me to experiment and learn + more about React and + especially Redux. It was developed + and compiled with webpack, and styled with help from{' '} + cssnext and{' '} + Lost. +

+

+ A smahr.net project /{' '} + Github +

+
+
+ Close +
+
+); export default class About extends React.Component { constructor(props) { @@ -29,7 +43,7 @@ export default class About extends React.Component { this.state = { modalOpen: false, - } + }; } toggleModal() { @@ -60,10 +74,21 @@ export default class About extends React.Component { return (
- +
- - {this.state.modalOpen ? : null} + + {this.state.modalOpen ? ( + + ) : null}
); diff --git a/src/components/ListHeader.js b/src/components/ListHeader.js index 54634d0..2453683 100644 --- a/src/components/ListHeader.js +++ b/src/components/ListHeader.js @@ -1,19 +1,15 @@ import React from 'react'; import TimeSpanMenu from './TimeSpanMenu'; -class ListHeader extends React.Component { - render() { - return ( -
-

{this.props.title}

- -
- ); - } -} +const ListHeader = ({ title }) => ( +
+

{title}

+ +
+); ListHeader.propTypes = { title: React.PropTypes.string.isRequired, -} +}; export default ListHeader; diff --git a/src/components/Menu.js b/src/components/Menu.js index 7fec136..64978f0 100644 --- a/src/components/Menu.js +++ b/src/components/Menu.js @@ -1,21 +1,23 @@ import React from 'react'; import { Link, IndexLink } from 'react-router'; -export default class Explore extends React.Component { - constructor(props) { - super(props); - } +const Menu = () => ( + +); - render() { - return ( - - ); - } -} +export default Menu; diff --git a/src/components/NowPlaying.js b/src/components/NowPlaying.js index 48dbc59..e0cf0af 100644 --- a/src/components/NowPlaying.js +++ b/src/components/NowPlaying.js @@ -1,22 +1,15 @@ import React from 'react'; -import { Link } from 'react-router'; import SineWave from './SineWave'; -export default class NowPlaying extends React.Component { - constructor(props) { - super(props); - } +export default ({ track }) => { + const { name, artist } = track; - render() { - const {name, artist} = this.props.track; - - return ( -
-
Listening:
-

{name}

-

{artist.name}

- -
- ); - } -} + return ( +
+
Listening:
+

{name}

+

{artist.name}

+ +
+ ); +}; diff --git a/src/containers/App.js b/src/containers/App.js index 9fc2dcc..b435d13 100644 --- a/src/containers/App.js +++ b/src/containers/App.js @@ -3,24 +3,16 @@ import Header from '../containers/Header'; import About from '../components/About'; import LoaderWrapper from '../components/LoaderWrapper'; -class App extends React.Component { - constructor(props) { - super(props); - } - - render() { - return ( - -
- {this.props.children} - - - ); - } -} +const App = props => ( + +
+ {props.children} + + +); App.propTypes = { - children: React.PropTypes.node + children: React.PropTypes.node, }; export default App;