openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

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

Open Cellule opened this issue 1 year ago • 0 comments

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)

Cellule avatar Mar 14 '24 23:03 Cellule