import React from 'react'; import logo from './logo.svg'; import './App.css'; const axios = require('axios'); class App extends React.Component { constructor(props) { super(props); this.state = { status: 'LOADING' }; } componentDidMount() { const symbol = this.props.symbol; const url = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=demo`; axios.get(url). then(res => this.setState({ error: null, status: 'DONE', price: res.data['Global Quote']['05. price'] })). catch(err => this.setState({ error: err.message, status: 'ERROR', price: 'N/A' })); } render() { if (this.state.status === 'ERROR') { return (

Error: {this.state.error}

); } else if (this.state.status === 'DONE') { return (

Price: {this.state.price}

); } else { return (

Loading...

); } } } export default App;