<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
import React, { Component } from 'react';
class Twitch extends Component {
constructor(props) {
super(props)
this.state = {
requestFailed: false
}
}
componentDidMount() {
fetch('https://api.twitch.tv/kraken/videos/top?limit=5&sort=time&language=en', {
method: "GET",
headers: {
"Client-ID": "iy25o25wjejp9dg0g446t3dnnsu8aw",
},
}) //fetch returns a promise
.then(response => {
if (!response.ok) {
throw Error("Network request failed")
}
return response
})
.then(d => d.json()) //this is the equivalent of parse.json and d is the variable for the data
.then(d => {
this.setState({ //callback
theData: d
})
}, () => {
this.setState({
requestFailed: true
})
})
}
render() {
if (this.state.requestFailed) return <p>Failed!</p>
if (!this.state.theData) return <p>Loading...</p>
console.log(this.state.theData.videos);
return (
<div>
{this.state.theData.videos.map((videos, i) => <Dash
key={i} />)}
{this.state.theData.videos.map((thumbnails, i) => <Dash2
key={i} />)}
{this.state.theData.videos.map((fps, i) => <Dash2
key={i} />)}
{this.state.theData.videos.map((resolutions, i) => <Dash2
key={i} />)}
{this.state.theData.videos.map((channel, i) => <Dash2
key={i} />)}
{this.state.theData.videos.map((_links, i) => <Dash2
key={i} />)}
</div>
)
}
}
class Dash extends Component {
render() {
return (
<div>
<div>{this.state.theData.videos.title}</div>
<div>{this.state.theData.videos.url}</div>
</div>
)
}
}
class Dash2 extends Component {
render() {
return (
<div>
<div>{this.state.theData.videos.url}</div>
</div>
)
}
}
ReactDOM.render(<Twitch />, document.getElementById('root'));
registerServiceWorker();
//export default Twitch;
//<p>Loading...</p> works as the only item in render(), but if 'if (!this.state.githubData)' is added, it breaks
//<h2>{this.state.githubData.name}</h2> this must be added also
//react-devtools in chrome