import React from "react";
const arr = [
{ id: 1, name: "apple" },
{ id: 2, name: "orange" },
{ id: 3, name: "grape" }
];
export default function App() {
const [items, setItems] = React.useState(arr);
const deleteItem = (index) => () =>
setItems((items) => items.filter((_, i) => i !== index));
return (
<>
{items.map((it, index) => {
return (
<div key={it.id}>
{it.name} <button onClick={deleteItem(index)}>delete</button>
</div>
);
})}
</>
);
}