From 7820cb0777d9d4c0479a926a06811c945f35654f Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 30 Apr 2023 11:56:29 -0400 Subject: ex2.8 handle phone numbers --- part2/phonebook/src/App.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/part2/phonebook/src/App.js b/part2/phonebook/src/App.js index 2843875..15f9636 100644 --- a/part2/phonebook/src/App.js +++ b/part2/phonebook/src/App.js @@ -5,7 +5,7 @@ const ShowPerson = (props) => { return (
    {persons.map( (person) => { - return (
  1. {person.name}
  2. ) + return (
  3. {person.name} {person.phoneNumber}
  4. ) } )}
) @@ -13,9 +13,10 @@ const ShowPerson = (props) => { const App = () => { const [persons, setPersons] = useState([ - { name: 'Arto Hellas' } + { name: 'Arto Hellas', phoneNumber: '000-000-0000' } ]) const [newName, setNewName] = useState('') + const [phoneNumber, setPhoneNumber] = useState('') const addContact = (event) => { event.preventDefault() @@ -26,14 +27,19 @@ const App = () => { const newPerson = { name: newName, id: persons.length + 1, + phoneNumber: phoneNumber, } setPersons(persons.concat(newPerson)) }} const handleTypedName = (event) => { - console.log(event.target.value) + //console.log(event.target.value) setNewName(event.target.value) - console.log(newName) + //console.log(newName) + } + + const handlePhoneNo = (event) => { + setPhoneNumber(event.target.value) } return ( @@ -41,7 +47,8 @@ const App = () => {

Phonebook

- name: +

name:

+

number:

-- cgit v1.2.3