eyalllE
tRPC4y ago
1 reply
eyalll

Prefetch forEach

Hello, I'm trying to prefetch a list of procedures like this

type QueryKeys = {
  // how to type this?
  path: [string, string];
  params: Partial<{ [key in keyof Key]: string }>;
};

const prefetchProcedures = (ids: QueryKeys[]) => {
  const utils = trpc.useContext();
  // [{path:["zones", "allSectors"], params: { zoneId: z.id }},{path: ["sectors", "allWalls"], params: { sectorId: s.id }]}
  ids.forEach((i) => {
    utils[i.path[0]][i.path[1]].prefetch(i.params);
  });
};


How can typesafe the path of the router and the procedure?
Was this page helpful?