better naming

master
Matt Huntington 5 years ago
parent 507a6671d3
commit 8e0de6d865

@ -1,4 +1,4 @@
todo: instructions, better naming, test clone/deploy todo: instructions, test clone/deploy
# Getting Started with Create React App # Getting Started with Create React App

@ -1,7 +1,7 @@
import './App.css'; import './App.css';
import React from 'react'; import React from 'react';
import axios from 'axios'; import axios from 'axios';
import Person from './components/person.js' import Contact from './components/contact.js'
class App extends React.Component { class App extends React.Component {
@ -9,7 +9,7 @@ class App extends React.Component {
contacts: [] contacts: []
} }
getPeople = ()=>{ getContacts = ()=>{
axios axios
.get('https://desolate-thicket-29906.herokuapp.com/api/contacts') .get('https://desolate-thicket-29906.herokuapp.com/api/contacts')
.then((response)=>{ .then((response)=>{
@ -20,32 +20,32 @@ class App extends React.Component {
} }
componentDidMount = ()=>{ componentDidMount = ()=>{
this.getPeople(); this.getContacts();
} }
createUser = (event)=>{ createContact = (event)=>{
event.preventDefault(); event.preventDefault();
axios axios
.post( .post(
'https://desolate-thicket-29906.herokuapp.com/api/contacts', 'https://desolate-thicket-29906.herokuapp.com/api/contacts',
{ {
name:this.state.newPersonName, name:this.state.newContactName,
age:this.state.newPersonAge age:this.state.newContactAge
} }
).then(()=>{ ).then(()=>{
this.getPeople(); this.getContacts();
}) })
} }
changeNewPersonName = (event)=>{ changeNewContactName = (event)=>{
this.setState({ this.setState({
newPersonName: event.target.value newContactName: event.target.value
}) })
} }
changeNewPersonAge = (event)=>{ changeNewContactAge = (event)=>{
this.setState({ this.setState({
newPersonAge: event.target.value newContactAge: event.target.value
}) })
} }
@ -58,16 +58,16 @@ class App extends React.Component {
<ul> <ul>
{ {
this.state.contacts.map((contact)=>{ this.state.contacts.map((contact)=>{
return <Person refreshCallback={this.getPeople} data={contact} /> return <Contact refreshCallback={this.getContacts} data={contact} />
}) })
} }
</ul> </ul>
</section> </section>
<section> <section>
<h2>Create a new Contact</h2> <h2>Create a new Contact</h2>
<form onSubmit={this.createUser}> <form onSubmit={this.createContact}>
Name: <input type="text" onKeyUp={this.changeNewPersonName} /><br/> Name: <input type="text" onKeyUp={this.changeNewContactName} /><br/>
Age: <input type="number" onKeyUp={this.changeNewPersonAge} /><br/> Age: <input type="number" onKeyUp={this.changeNewContactAge} /><br/>
<input type="submit" value="Create Contact" /> <input type="submit" value="Create Contact" />
</form> </form>
</section> </section>

Loading…
Cancel
Save