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",
|
||||
"number": "0934023910",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"name": "Minh",
|
||||
"number": "023124",
|
||||
"id": 7
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import axios from 'axios'
|
||||
//import axios from 'axios'
|
||||
import Filter from './components/Filter'
|
||||
import PersonForm from './components/PersonForm'
|
||||
import Person from './components/Person'
|
||||
@@ -48,9 +48,9 @@ const App = () => {
|
||||
const check = persons.filter(person => person.name === newName )
|
||||
check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`)
|
||||
|
||||
if (check.length ===0) {
|
||||
axios
|
||||
.post('http://localhost:3001/persons', newPerson)
|
||||
if (check.length === 0) {
|
||||
Contact
|
||||
.updateContact(newPerson)
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
|
||||
@@ -8,18 +8,20 @@ const getContact = () => {
|
||||
return contact.then(response => response.data)
|
||||
}
|
||||
|
||||
/*
|
||||
const updateContact = newObject => {
|
||||
return axios.post(baseUrl, newObject)
|
||||
|
||||
const updateContact = newPerson => {
|
||||
const contact = axios.post(baseUrl, newPerson)
|
||||
return contact.then(response => response.data)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
const update = (id, newObject) => {
|
||||
return axios.put(`${baseUrl}/${id}`, newObject)
|
||||
}*/
|
||||
|
||||
const Contact = {
|
||||
getContact
|
||||
getContact, updateContact
|
||||
}
|
||||
|
||||
export default Contact
|
||||
Reference in New Issue
Block a user