// Extract form element into its own component import { useState } from 'react' const ShowPerson = (props) => { const searchTerm = props.searchTerm const persons = props.persons if (searchTerm === undefined) { return persons.map( (person) => { return (
  • {person.name} {person.phoneNumber}
  • )}) } else { const searchedList = persons.filter( (person) => {return person.name.includes(props.searchTerm)}); console.log(searchedList) return searchedList.map( (searched) => { return (
  • {searched.name} {searched.phoneNumber}
  • ) } ) } } const Filter = (props) => { return (

    filter shown with props.setSearchTerm(event.target.value)} />

    ) } const App = () => { const [persons, setPersons] = useState([ { name: 'Arto Hellas', phoneNumber: '000-000-0000', id: 1 }, { name: 'John F Kennedy', phoneNumber: '1-800-NASA', id: 2 }, { name: 'Julius K Nyerere', phoneNumber: '1-800-UHURU', id: 3 }, ]) const [newName, setNewName] = useState('') const [phoneNumber, setPhoneNumber] = useState('') const [searchTerm, setSearchTerm] = useState('') const addContact = (event) => { event.preventDefault() console.log(newName, persons) if (persons.find(person => person.name === newName)) { alert(`${newName} is already added to phonebook`) } else { const newPerson = { name: newName, id: persons.length + 1, phoneNumber: phoneNumber, } setPersons(persons.concat(newPerson)) }} const handleTypedName = (event) => { //console.log(event.target.value) setNewName(event.target.value) //console.log(newName) } const handlePhoneNo = (event) => { setPhoneNumber(event.target.value) } return (

    Phonebook

    add new contact

    name:

    number:

    Numbers

    ) } export default App