Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created October 17, 2018 06:00
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 amandeepmittal/59c86a95c9d89833b7e1c5d8bc2552f6 to your computer and use it in GitHub Desktop.
Save amandeepmittal/59c86a95c9d89833b7e1c5d8bc2552f6 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
state = {
data: []
};
componentDidMount() {
this.fetchData()
.then(res => this.setState(res))
.catch(err => console.log(err));
}
fetchData = async () => {
const response = await fetch('/mock');
const body = response.json();
return body;
};
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1>Data from the Backend</h1>
{this.state.data.map(person => (
<p key={person.id}>
Name: {person.name} <br /> Age: {person.age}
</p>
))}
</header>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment