I have currently this array of objects like this:
const data = [
{
name: "jack",
number: 3,
isEnabled: false,
},
{
name: "Daniel",
number: 5,
isEnabled: false,
},
{
name: "John",
number: 6,
isEnabled: false,
},
];
Inside the render I have mapped the data array to return some divs:
{
data.map((d) => {
return (
<div onClick={() => pushClickedNumbers(d.number)}>
`${d.name}${d.number}`
</div>
);
});
}
Now I would like to create a function to push that number inside another array state, every time i click on that div, and to remove it when I click again. I've tried something like this to add, but I can't figure it out how to remove it:
const pushClickedNumber = (number) => {
setArrayOfNumbers(number, ...arrayOfNumbers);
};
The state get populated with the div clicked, but I'm struggling to find a way to remove the same number when I click again on the same div. Thank you
onClickfunction?