From f18a52307760f7d9b91d9399949ec79eceb892bd Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Tue, 2 May 2023 19:54:15 -0400 Subject: ex2.12 store contacts locally and on a local database --- part2/phonebook/src/App.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'part2/phonebook/src') diff --git a/part2/phonebook/src/App.js b/part2/phonebook/src/App.js index 7edf5a8..b8de8a6 100644 --- a/part2/phonebook/src/App.js +++ b/part2/phonebook/src/App.js @@ -31,19 +31,15 @@ const Filter = (props) => { } const App = () => { - //const [persons, setPersons] = useState([ - //{ name: 'Arto Hellas', number: '000-000-0000', id: 1 }, - //{ name: 'John F Kennedy', number: '1-800-NASA', id: 2 }, - //{ name: 'Julius K Nyerere', number: '1-800-UHURU', id: 3 } - //]) const [persons, setPersons] = useState([]) const [newName, setNewName] = useState('') const [number, setPhoneNumber] = useState('') const [searchTerm, setSearchTerm] = useState('') + const baseURL = 'http://localhost:3001/persons' useEffect(() => { axios - .get('http://localhost:3001/persons') + .get(baseURL) .then(response => { console.log('promise fulfilled') setPersons(response.data) @@ -62,6 +58,11 @@ const App = () => { id: persons.length + 1, // eslint-disable-next-line number: number } + // store new person locally and on the local server + axios + .post(baseURL, newPerson) + .then(response => + console.log(response)) setPersons(persons.concat(newPerson)) } } -- cgit v1.2.3