usestate array delete
const removeProduct = (index) => {
setProductsArray([
...products.slice(0, index),
...products.slice(index + 1, products.length)
]);
}
usestate array delete
const removeProduct = (index) => {
setProductsArray([
...products.slice(0, index),
...products.slice(index + 1, products.length)
]);
}
usestate remove from array
const defaultList = [
{ name: "ItemOne" },
{ name: "ItemTwo" },
{ name: "ItemThree" }
];
const [list, updateList] = useState(defaultList);
const handleRemoveItem = (e) => {
const name = e.target.getAttribute("name")
updateList(list.filter(item => item.name !== name));
};
remove element from array in usestate
let index = array.indexOf(e.target.value)
if (index !== -1) {
array.splice(index, 1);
setState(array);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us