`> import { useState } from “react”;
const App = () => {
const [persons, setPersons] = useState([{ name: “Lucky Fin” }]);const [newName, setNewName] = useState(” “);
const addName = (event) => {
event.preventDefault();
console.log(‘button clicked’, event.target)
const personObject = {
name: newName,};
const duplicateFound = persons.find(
(person) => person.name === personObject.name
);console.log(“duplicate found”, duplicateFound);
if (duplicateFound) {
alert(${personObject.name} is already in the phonebook
);
else {
setPersons(persons.concat(personObject));}
console.log(“in addName, persons:”, persons);
setNewName(” “);
};
const handleNameAddition = (event) => {
console.log(“in handleNameAddition”, event.target.value);setNewName(event.target.value);
};
return (
Phonebook
Name:
Add
Numbers:
{persons.map((person) => (
{person.name}
))});
};export default App;
`
Can someone help me understand where I have gone wrong?
user25531687 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.