-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Problem:
I have a use case were a component would ideally consume a dynamic number of queries. For example, building a table where each column is populated by data from different queries but the user can select from a large list which columns will be populated at any one time. Ideally the data for each column would be queried individually in the parent component and passed to the table together, but the number of hooks within a component needs to be constant.
Is there a clean way to do this with the current API?
Current work arounds I've tried:
-
Use a single useQuery with a fetching function that behind the scenes can dynamically fire all the necessary fetch calls based on the user selection. The downside with this is if the user removes or adds a single column, the query key doesn't match and all of the data needs to be refetched even if some sub-queries aren't stale.
-
Move the useQueries into the columns directly or other separate components so they mount individually. Here the downsides are either limitations on how we can implement the table or hard to read and manage code.
Proposed feature:
Assuming I am not missing another way to do this, either a new hook useQueryArray or expansion of useQuery that accepts an array of keys and functions that are each individually cached.