Skip to content

Array of queries hook #138

@krashdifferent

Description

@krashdifferent

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions