trying to fetch data

This commit is contained in:
Niel 2019-02-06 23:30:58 +01:00
parent 142ca7e6de
commit 70c7aa60dc
5 changed files with 51 additions and 46 deletions

View file

@ -1,32 +1,7 @@
body {
background-color: pink;
}
.App { .App {
text-align: center; text-align: center;
} }
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View file

@ -1,25 +1,16 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import logo from './logo.svg';
import Channels from './components/channels/Channels';
import Header from './components/Header/Header';
import './App.css'; import './App.css';
class App extends Component { class App extends Component {
render() { public render() {
return ( return (
<div className="App"> <div className='App'>
<header className="App-header"> <Header />
<img src={logo} className="App-logo" alt="logo" /> <Channels />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div> </div>
); );
} }

View file

@ -0,0 +1,10 @@
.App-header {
background-color: #282c34;
min-height: 100px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

View file

@ -0,0 +1,9 @@
import React, { Component } from 'react';
import './Header.css';
class Header extends Component {
public render() {
return <div className='App-header'>Cliffbreak.de</div>;
}
}
export default Header;

View file

@ -0,0 +1,20 @@
import React, { Component } from 'react';
export default class Channels extends Component<any, any> {
constructor(props: any) {
super(props);
this.state = {
data: 'Loading...',
};
}
componentDidMount() {
fetch('https://ts.cliffbreak.de/v1/channels')
.then(response => response.json())
.then(data => this.setState({ data }));
}
public render() {
const { data } = this.state;
return <div>{data}</div>;
}
}