Skip to content

Conversation

@MishaKazakov
Copy link

Adds types for useQueries beacus previously it was not possible to type the result of useQueries

@vercel
Copy link

vercel bot commented Aug 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/HornbqK5qYvN7KPhKsP3N2AQ6rwr
✅ Preview: https://react-query-git-fork-mishakazakov-master-tannerlinsley.vercel.app

import { UseQueryOptions, UseQueryResult } from './types'

export function useQueries(queries: UseQueryOptions[]): UseQueryResult[] {
export function useQueries<TData = unknown, TError = unknown>(queries: UseQueryOptions[]): UseQueryResult<TData,TError>[] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I don't think it's that easy. we've had an open PR here that didn't quite make it: #1527

and there is an open issue with lots of discussions here: #1675

one problem is that every query in useQueries can have it's own type. It's not only for fetching N times the same query, I can also do:

useQueries([
  { queryKey: 'foo', queryFn: fetchFoo },
  { queryKey: 'bar', queryFn: fetchBar },
] as const)

where the result type should be ideal a tuple: [UseQueryResult<Foo>, UseQueryResult<Bar>]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I was too hopeful that it would be easy.

Thanks for your time. closing the pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants