I'm relatively new to TS, and I'm running into a weird issue. I seem to have defined everything, but it doesn't seem to recognize my typing for the data.
Here is what I have:
const Component = () => {
const [data, setData] = React.useState([[], []])
React.useEffect(() => {
fetchData()
}, [])
const fetchData = React.useCallback(async () => {
const data = await fetchDataController()
setData(data)
^^^^ error
})
}
This throws the error,
Argument of type 'Element[][]' is not assignable to parameter of type 'SetStateAction<never[][]>'
Type 'Element[][]' is not assignable to type 'never[][]'
Type 'Element[]' is not assignable to type 'never[]'
Type 'Element is not assignable to type 'never'
My function fetchDataController return an array of arrays of elements.
My type is as follows:
type TData = {
id: string,
desc: string
}
I've tried doing something like,
const [data, setData] = React.useState<Array<TData[], TData[]>>([[], []])
But that didn't seem to work. What am I missing here?