Here is a code snippet:
import { QueryClient, useQuery, useQueryClient, UseQueryOptions } from "@tanstack/react-query"
export function useQueryFactory(getConfig: (queryClient: QueryClient) => UseQueryOptions) {
const queryClient = useQueryClient()
const config = getConfig(queryClient)
return useQuery(config)
}
class Account {
static findMany() {
return {
async queryFn() {
return {
accounts: [{
id: 123
}],
}
},
queryKey: ["Country", "findMany"],
}
}
}
export function AccountsList() {
const { isSuccess, data } = useQueryFactory(Account.findMany)
if (isSuccess) {
// error here Property 'accounts' does not exist on type 'unknown'
const { accounts } = data
console.log(accounts)
}
}
Can anyone explain why this error occurred and how to fix it?