How to delete multiple items of array and set state? I have selected multiple items from checkbox. This is the selected item [5, 4, 3] I want to remove all items in array based on id and update the state. This is my code.
const [products, setProducts] = useState();
const DeleteProducts = () => {
const selectedItems = [5, 4, 3];
selectedItems.forEach(function(p) {
setProducts(products.filter(prd => prd.id !== p));
});
}
Its removing only one item at time, but I selected 3 items. How to remove 3 selected items and products state? Thanks