diff --git a/src/App.js b/src/App.js index 2d7e652..b236bee 100644 --- a/src/App.js +++ b/src/App.js @@ -9,7 +9,7 @@ class App extends React.Component { contacts: [] } - componentDidMount = ()=>{ + getPeople = ()=>{ axios .get('https://desolate-thicket-29906.herokuapp.com/api/contacts') .then((response)=>{ @@ -19,6 +19,10 @@ class App extends React.Component { }) } + componentDidMount = ()=>{ + this.getPeople(); + } + createUser = (event)=>{ event.preventDefault(); axios @@ -29,13 +33,7 @@ class App extends React.Component { age:this.state.newPersonAge } ).then(()=>{ - axios - .get('https://desolate-thicket-29906.herokuapp.com/api/contacts') - .then((response)=>{ - this.setState({ - contacts:response.data - }) - }) + this.getPeople(); }) } @@ -60,7 +58,7 @@ class App extends React.Component { diff --git a/src/components/person.js b/src/components/person.js index ec7a443..b2773cf 100644 --- a/src/components/person.js +++ b/src/components/person.js @@ -3,10 +3,18 @@ import axios from 'axios'; class Person extends React.Component { + deletePerson = ()=>{ + axios + .delete( + `https://desolate-thicket-29906.herokuapp.com/api/contacts/${this.props.data.id}` + ).then(()=>{ + this.props.refreshCallback(); + }) + } render = ()=>{ return
  • {this.props.data.name} is {this.props.data.age} years old - +
  • } }