mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-06-05 15:08:33 +09:00
Completed 2.7 (phonebook step2)
This commit is contained in:
@@ -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('')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user