mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-07-18 14:03:24 +09:00
Completed 2.7 (phonebook step2)
This commit is contained in:
@@ -16,7 +16,12 @@ const App = () => {
|
|||||||
const newPerson = {
|
const newPerson = {
|
||||||
name: newName
|
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('')
|
setNewName('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user