Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New usePrepare<Op> hook to enable reactQuery.useQueries #233

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cellule
Copy link

@Cellule Cellule commented Mar 14, 2024

The feature I'm looking for is to have a type-safe reliable way to use useQueries.
I thought about using ReactQueryFunctions instead of ReactQueryComponents. However, having a mix of both (see #232) is not ideal and causes to have a whole lot of duplicated code.
Since I prefer the hook approach, I wanted a way to make this work.
In the current state it is impossible to extract all the goodies provided by the use<Op> hook, namely the useContext, the queryKey and queryFn.

My proposed solution is to make a new hook call usePrepare<Op> that returns a function (factory) to then create the queryKey/queryFn from variables.
I'm open to suggestions on naming, not totally sold on it

This is the end result I'm looking for in my app

  const query = useComponentControllerFindOne({ pathParams: id });
  const findOnePackage = usePreparePackageControllerFindOne({});
  const queries = useQueries({
    queries: query.data?.listIds.map((id) => findOnePackage({ pathParams: { id } })) || [],
  });
  const packages = queries.map(q => q.data)

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.

None yet

1 participant