I have a dynamically rendered component, with its own key, stored in an array of objects. This component has a delete button, that ideally would delete the element from its key from the array. However I can't wrap my head around it. Should the delete function be in the container or in the component? I tried different things but nothing seems to work. Right now I have:
Array of objects in the container:
const [weight, setWeight] = useState([{name: 34, value: "321iuiv51234"},{name: 38, value: "jkxdxb55s"}]);
And the dynamically rendered component, where the trash bin img should trigger a function to delete the component.
import React from "react";
import "./Weight.css";
import trashbin from "../img/trash-bin.png";
const Weight = ({}) => {
return (
<div className="weight-box">
<p>{weight} kg</p>
<p></p>
<img src={trashbin} alt="trash bin" className="trash-bin" />
</div>
);
};
export default Weight;
Any ideas? Thank you!