Skip to content

Instantly share code, notes, and snippets.

@alivesay
Created October 20, 2018 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alivesay/b87dfa47fbbfd591db00018ce3c50d67 to your computer and use it in GitHub Desktop.
Save alivesay/b87dfa47fbbfd591db00018ce3c50d67 to your computer and use it in GitHub Desktop.
1 import React, { Component } from 'react';
2
3 function handleErrors(response) {
4 if (!response.ok) {
5 throw Error(response.statusText);
6 }
7 return response;
8 }
9
10
11 class Status extends Component {
12 constructor(props) {
13 super(props);
14
15 this.state = {
16 data: null,
17 };
18 }
19
20 componentDidMount() {
21 fetch("http://localhost:3001/v1/api/status")
22 .then(handleErrors)
23 .then(response => response.json())
24 .then(data => this.setState({ data }))
25 .catch(error => console.log(error));
26 }
27
28 render() {
29 console.log(this.state);
30 return <h1>Server Status: {this.state.data}</h1>;
31 }
32 }
33
34 export default Status;
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment