I'm building little app in React and I have a problem to remove and object from Array after I click on icon.
I have form with inputs and when user fill this inputs and click on a button then inputs will into an array. I have array in a state and the default is empty array.
const [attendees, setAttendees] = useState([]);
I have a function for delete a object from array after I click on icon
const deleteAttendee = (attendee) => {
setAttendees({
attendees: attendees.filter(
(element) => element.firstName !== attendee.firstName
),
});
};
but there is a problem when I clicked on icon I get an error. That map is not a function.
I have in another component map function for rendering each user from the inputs
<div className="attendee-container">
{attendees.map((_attendee, index) => {
return (
<div key={index}>
<div onClick={() => deleteAttendee(_attendee)}>{trashAltIcon}</div>
<h3>
{index + 1}. {_attendee.firstName} {_attendee.lastName} (
{_attendee.age})
</h3>
</div>
);
})}
</div>
Thank you in advance for your help.