From 974a4b878b10882a116bfd748f655c68ffd23ad7 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Wed, 22 Jul 2020 21:22:32 -0500 Subject: fetch-MSFT-stockprice-API-request-react.js --- fetch-MSFT-stockprice-API-request-react.js | 41 ++++++++++++++++++++++++++++++ mymodule.js | 2 ++ scratch.js | 11 ++++++++ scratch2.js | 0 4 files changed, 54 insertions(+) create mode 100644 fetch-MSFT-stockprice-API-request-react.js create mode 100644 mymodule.js create mode 100644 scratch2.js diff --git a/fetch-MSFT-stockprice-API-request-react.js b/fetch-MSFT-stockprice-API-request-react.js new file mode 100644 index 0000000..1df838f --- /dev/null +++ b/fetch-MSFT-stockprice-API-request-react.js @@ -0,0 +1,41 @@ +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; diff --git a/mymodule.js b/mymodule.js new file mode 100644 index 0000000..93edce4 --- /dev/null +++ b/mymodule.js @@ -0,0 +1,2 @@ + +exports.getName = () => "Kyle" \ No newline at end of file diff --git a/scratch.js b/scratch.js index f19d931..0e2de0a 100644 --- a/scratch.js +++ b/scratch.js @@ -74,3 +74,14 @@ String.prototype.format = function() { console.log('Is that a %s or a %s?... No, it\'s %s!'.format('plane', 'bird', 'SOman')); console.log((function(){}).constructor); + + +fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo').then(res => { + return res.json(); +}).then(price => console.log(price)); + + +const { getName } = require('./mymodule'); +console.log(getName()); + +console.log("ayy lmao".toUpperCase()); diff --git a/scratch2.js b/scratch2.js new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3