Skip to content
Advertisement

Removing Elements through button click within a map function?

I’m building a todo application in which all elements are inserted in a list of objects and then mapped using the map() function. I’m attempting to add a button with every map, that once clicked – will delete the specific element from the list. I’ve read quite a bit of documentation relating to the connection of useState and map(), but I’m still confused in how to implement this, and connect the specific element to the removal.

JavaScript

Advertisement

Answer

As per your explanation, I kind of understand you have todo items and you need to remove an item by clicking the remove button so I have made one working demo to take dummy items and remove it, Kindly check the below code to remove items.

list.js

JavaScript

app.js

JavaScript

working demo link: https://stackblitz.com/edit/react-n4z2qj?file=src/App.js

Advertisement