I have two custom hooks for using useQuery.
The second hook depends on the result of the first
While the first hook is being executed its data is undefined
interface Props {
id: number
enabled: boolean | undefined
}
export const getFooQuery = (props: Props) => {
const { id, enabled } = props
return {
queryKey: ['foo', id],
queryFn: () => fetchFoo({ id }),
staleTime: 10000,
enabled
}
}
export const useGetFoo= ({ id, enabled }: Props) => {
const queryResult = useQuery(getFooQuery({ id, enabled }))
return queryResult
}
export const App = () => {
const {data: dataBar} = useGetBar()
const {data: dataFoo} = useGetFoo({id: dataBar?.id, enabled: dataBar?.id})
//^ number | null | undefined
//...
}
i have no idea. mb change type id to number | null | undefined, but then how to check it correctly