How to load multiple resources in parallel in master detail resources
I have an api where resources are organized hierarchically, I want to build sane breadcrumbs with proper links and text labels of the parent resources, but I need to load those resources first:
I am doing something like this
- Can I more elegantly extract parameters from the current route
/products/:product_id:/customers/:customer_id/:roles/:id
?
- Can I load in parallel instead of multiple useOne
, using something like this https://tanstack.com/query/v4/docs/framework/react/guides/parallel-queries I could try to build an useResources
, but I need to replicate same actions that useOne
is doing ?2 Replies
Hi @i.stoica. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To extract parameters from the current route more elegantly, you can use the
useParsed
hook provided by Refine. This hook allows you to parse the current URL and extract the parameters. Here is an example:
Source: Refine Documentation (https://refine.dev/docs/data/hooks/use-show#resource)
As for loading multiple resources in parallel, Refine's useOne
hook is an extended version of TanStack Query's useQuery
that supports all of its features. Therefore, you can use the useQueries
function from TanStack Query to fetch multiple resources in parallel. However, please note that this approach might require additional configuration and error handling.
Unfortunately, the provided extracts do not contain a specific example of using useQueries
with Refine's useOne
hook. For more detailed information, you might want to refer to the Refine Documentation (https://refine.dev/docs/data/hooks/use-one) and the TanStack Query Documentation (https://tanstack.com/query/v4/docs/react/reference/useQueries).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@180601470268211200> kapa.ai is still learning and improving, please let us know how it did by reacting below