tRPCttRPC
Powered by
eyalllE
tRPC•4y 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);
  });
};
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?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Prefetch | useSuspenseQuery | Error: redacted | updateDehydratedSuspenseComponent
yWilliamYyWilliam / ❓-help
2y ago
Recommended way to prefetch client-side
pbeshPpbesh / ❓-help
4y ago
Error using prefetch query with TanStack Query
coder2000Ccoder2000 / ❓-help
11mo ago