mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-06-05 15:08:33 +09:00
Completed 2.16 (fix error)
This commit is contained in:
@@ -29,6 +29,11 @@
|
|||||||
"name": "Thao",
|
"name": "Thao",
|
||||||
"number": "0934023910",
|
"number": "0934023910",
|
||||||
"id": 6
|
"id": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Minh",
|
||||||
|
"number": "023124",
|
||||||
|
"id": 7
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import axios from 'axios'
|
//import axios from 'axios'
|
||||||
import Filter from './components/Filter'
|
import Filter from './components/Filter'
|
||||||
import PersonForm from './components/PersonForm'
|
import PersonForm from './components/PersonForm'
|
||||||
import Person from './components/Person'
|
import Person from './components/Person'
|
||||||
@@ -48,9 +48,9 @@ const App = () => {
|
|||||||
const check = persons.filter(person => person.name === newName )
|
const check = persons.filter(person => person.name === newName )
|
||||||
check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`)
|
check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`)
|
||||||
|
|
||||||
if (check.length ===0) {
|
if (check.length === 0) {
|
||||||
axios
|
Contact
|
||||||
.post('http://localhost:3001/persons', newPerson)
|
.updateContact(newPerson)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,18 +8,20 @@ const getContact = () => {
|
|||||||
return contact.then(response => response.data)
|
return contact.then(response => response.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
const updateContact = newObject => {
|
const updateContact = newPerson => {
|
||||||
return axios.post(baseUrl, newObject)
|
const contact = axios.post(baseUrl, newPerson)
|
||||||
|
return contact.then(response => response.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
const update = (id, newObject) => {
|
const update = (id, newObject) => {
|
||||||
return axios.put(`${baseUrl}/${id}`, newObject)
|
return axios.put(`${baseUrl}/${id}`, newObject)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
const Contact = {
|
const Contact = {
|
||||||
getContact
|
getContact, updateContact
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Contact
|
export default Contact
|
||||||
Reference in New Issue
Block a user