The alert doesn't come up the first time i submit a repeated value and the alert doesn't show the name
const addName = (event) => {
event.preventDefault()
const nameObject = {
name: newName
}
const temp = persons.filter(
person => person.name === nameObject.name
)
if (temp === undefined || temp.length === 0) {
setPersons(persons.concat(nameObject))
setNewName('')
} else {
console.log(nameObject.name)
alert(`${nameObject.name} already exists in phonebook`)
}
}
Aucun commentaire:
Enregistrer un commentaire