[DOC] Dependent Queries
See original GitHub issueIs this issue related to an existing part of the documentation? If so, please provide a link
- Added helpful info on using dependent queries from React Query.
- Refine documentation page: https://refine.dev/docs/core/hooks/data/useMany/
- React query documentation page: https://react-query.tanstack.com/guides/dependent-queries
Describe the thing to improve
Dependent query is useful in a case where there are queries that depend on a preceding query’s results. This can be added to the Refine documentation to make the documentation more robust.
Personally, I ran into a problem where I had 5 queries, 4 of which depend on the first query’s result. What happens is all 5 queries appear to run synchronously on load and 4 error messages popped up once before running successfully for the second time. The random error messages popping up can be distracting for the end user. This issue can be resolved with the use of dependent queries from React Query’s useQuery options.
Describe the solution (optional)
I can create a pull request and add the following to the documentation:
:::tip
useQuery
options also allows you to implement dependent query whereby a query is only executed after a particular query result is fetched. This is particularly useful if you have queries that are dependent on the query results of a preceding query.
Refer to react-query docs on dependent queries for more information.
- Suppose you want this query to run after
id_query_result
is fetched by a preceding query, you can setenabled
to!!id_query_result
.
const categoryQueryResult = useMany<ICategory>({
resource: "categories",
ids: ids_query_result,
queryOptions: { enabled: !!id_query_result },
});
:::
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
Hey @thatjosh 👋, Looks so cool! Thank you!
Hello @omeraplak, Thank you for the prompt response as well as taking the time to review this! I think you have a better perspective on how the information should be outlined in the documentation! As a beginner & an end user, it didn’t occur to me that this information was on this page, so perhaps it might be a good idea for the information to be more accessible with the search function. That could perhaps be achieved by making this more specific.