I have a parent component (App.tsx). In this component I'm defining a hook that holds and sets an array of numbers:
const [valuesList, setValuesList] = useState<number[]>([]);
for a previous childcomponent (AddNumber.tsx) I defined a function that adds a number to the array of numbers:
const addNumberToList = (num: number) => {
setValuesList((prev) => prev.concat(num));
};
then I passed the function to the child component. That worked fine.
However now I need to create a function to delete a number from the array.
Does anyone now how to implement that function?
In a previous app I implemented deleting a number from the list like this:
setValuesList(valuesList.filter((e) => e !== value));
But because I'm using TypeScript, I can't do it like that anymore, because I need to pass the deleteNumberFromList method to the childcomponent(NumberList.tsx)
Thanks for your help,
Anthony