I want to pass a setter hook (setValuesList) from the parent (App.tsx) to the childcomponent (AddNumber.tsx)
I defined the hook in the parent component like this:
const [valuesList, setValuesList] = useState<number[]>([]);
And I want to pass the hook to the childcomponent like this:
<AddNumber valuesList={valuesList} setValuesList={setValuesList} />
However I get a Typescript error:
(JSX attribute) AppProps.setValuesList: (num: number) => void
Type 'Dispatch<SetStateAction<number[]>>' is not assignable to type '(num: number) => void'.
Types of parameters 'value' and 'num' are incompatible.
Type 'number' is not assignable to type 'SetStateAction<number[]>'.ts(2322)
AddNumber.tsx(5, 3): The expected type comes from property 'setValuesList' which is declared here on type 'IntrinsicAttributes & AppProps'
In the childcomponent I am defining an interface for the props like this:
interface AppProps {
valuesList: number[];
setValuesList: (num: number) => void;
}
Does anyone see what I am doing wrong here?
my repository is at: https://github.com/acandael/number-list
Thanks for your help,
Anthony