/* eslint no-use-before-define: 0 */ // --> OFF import { useEffect, useState } from 'react' import personService from './services/persons' const ShowPerson = (props) => { const searchTerm = props.searchTerm const persons = props.persons if (searchTerm === undefined) { return persons.map((person) => { return (
  • {person.name} {person.number}
  • ) }) } else { const searchedList = persons.filter((person) => { return person.name.includes(props.searchTerm) }); console.log(searchedList) return searchedList.map( (searched) => { return (
  • {searched.name} {searched.number}
  • ) }) } } const Filter = (props) => { return (

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

    ) } const App = () => { const [persons, setPersons] = useState([]) const [newName, setNewName] = useState('') const [number, setPhoneNumber] = useState('') const [searchTerm, setSearchTerm] = useState('') useEffect(() => { personService .getAll() .then(response => { setPersons(response.data) }) }) const addContact = (event) => { event.preventDefault() console.log(newName, persons) if (persons.find(person => person.name === newName)) { // eslint-disable-next-line alert(`${newName} is already added to phonebook`) } else { const newPerson = { name: newName, id: persons.length + 1, // eslint-disable-next-line number: number } // store new person locally and on the local server personService .create(newPerson) .then(response => console.log(response)) 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