Completed 2.7 (phonebook step2)

This commit is contained in:
2021-08-27 20:39:33 +07:00
parent 7edc7c319f
commit 5b5837770a
+6 -1
View File
@@ -16,7 +16,12 @@ const App = () => {
const newPerson = {
name: newName
}
setPersons(persons.concat(newPerson))
// Check if newName already added to phonebook or not
const check = persons.filter(person => person.name === newName )
check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`)
setNewName('')
}