systematic-tanS
Refine2y ago
3 replies
systematic-tan

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

  const { id, resource } = useResource();
  const match = useMatch(`${resource?.list}`);
  const customer_id = match?.params.customer_id ?? "";
  const product_id = match?.params.product_id ?? "";
  const meta = useMemo(
    () => ({
      customer_id,
      product_id,
    }),
    [customer_id, product_id]
  );

  const { data: customer, isLoading: customerIsLoading } = useOne({
    resource: "customers",
    id: customer_id,
  });

  const { data: product, isLoading: productIsLoading } = useOne({
    resource: "products",
    id: product_id,
  });


- 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 ?
Was this page helpful?