-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Hi
With TanStack Query, I can subscribe to multiple queries in one hook call
https://tanstack.com/query/v5/docs/framework/react/reference/useQueries
It is useful for when I only know which queries I want to fetch at runtime.
Because of the rule of hooks, I can't call the useRead hook conditionnally, therefore I can't have a component that accepts a list of queries, for example.
Currently, when working with typesaurus-react and needing to fetch data for multiple documents or execute several related queries in parallel within a React component, I need to call multiple useRead, or manually orchestrating Promise.all with raw Typesaurus calls.
I know there is the many query to fetch multiple documents by ID, it doesn't cover scenarios where:
- You need to fetch multiple documents with different where clauses or from different collections.
- You want to combine the loading, error, and data states of these parallel queries into a single, cohesive result
Proposed solution
I propose adding a new hook, perhaps named useManyReads, to typesaurus-react that would function similarly to TanStack Query's useQueries.
This hook would accept an array of query configurations, each defining a specific Typesaurus read operation. It would then return an array of tuples containing the result and the loading/error state of its corresponding query