install axios, make call to api to populate contacts in DOM

master
Matt Huntington 5 years ago
parent a56ea7dbec
commit b98f79ab15

15763
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.11.4", "@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0", "@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10", "@testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"react": "^17.0.1", "react": "^17.0.1",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"react-scripts": "4.0.3", "react-scripts": "4.0.3",

@ -1,15 +1,35 @@
import logo from './logo.svg';
import './App.css'; import './App.css';
import React from 'react'; import React from 'react';
import axios from 'axios';
class App extends React.Component { class App extends React.Component {
state = {
contacts: []
}
componentDidMount = ()=>{
axios
.get('https://desolate-thicket-29906.herokuapp.com/api/contacts')
.then((response)=>{
this.setState({
contacts:response.data
})
}
)
}
render = ()=>{ render = ()=>{
return <main> return <main>
<h1>Contacts App</h1> <h1>Contacts App</h1>
<section> <section>
<h2>List of Current Conacts</h2> <h2>List of Current Conacts</h2>
<ul> <ul>
{
this.state.contacts.map((contact)=>{
return <li key={contact.id}>{contact.name} is {contact.age} years old</li>
})
}
</ul> </ul>
</section> </section>
<section> <section>

Loading…
Cancel
Save