diff --git a/src/components/QuoteOfTheDay.js b/src/components/QuoteOfTheDay.js index 39b7175..94e1ab7 100644 --- a/src/components/QuoteOfTheDay.js +++ b/src/components/QuoteOfTheDay.js @@ -1,44 +1,44 @@ -import React from 'react'; +import React from "react"; -import { QuotesRESTAPIUrl } from '../consts'; +import { QuotesRESTAPIUrl } from "../consts"; class QuoteOfTheDay extends React.Component { + constructor() { + super(); - constructor() { - super(); - - this.state = { - quote: { quote: "Loading...", author: null }, - }; - } - - componentWillMount() { - - this.getQuote().then(quote => this.setState({ quote })); - } - - getQuote = async () => { - - try { - const res = await fetch(QuotesRESTAPIUrl); - const data = await res.json(); - const { quote, author } = data['contents']['quotes'][0]; - return { quote, author }; - } catch (e) { - return { quote: `GET ${QuotesRESTAPIUrl} 429 (Too Many Requests)`, author: "quotes.rest" }; - } + this.state = { + quote: { quote: "Loading...", author: null } }; - - render() { - - const { quote, author } = this.state.quote; - - return ( -
{quote}
{(author !== null) ?—{author}
: null} -{quote}
+ {author !== null ?—{author}
: null} +