/* eslint no-use-before-define: 0 */ // --> OFF import { useEffect, useState } from 'react' import axios from 'axios' 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([ //{ 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('') useEffect(() => { axios .get('http://localhost:3001/persons') .then(response => { console.log('promise fulfilled') setPersons(response.data) console.log(persons) }) }) 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 } 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