-
-
Save amandeepmittal/59c86a95c9d89833b7e1c5d8bc2552f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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