Step 4

When the App is mounted, we fetch the quote of the day and update the state!

componentDidMount() { API.getTodayQuote() .then((data) => { this.setState(data); }) .catch((err) => { console.log(err); }); }

The operations to communicate withe the API are abstracted in the services/api file. For example, here is the implementation of getTodayQuote:

export async function getTodayQuote() { const response = await axios.get(`${BASE_URL}/today/${API_KEY}`); return { quote: response.data[0].q, author: response.data[0].a, }; }