tRPCttRPC
Powered by
SidS
tRPC•13mo ago•
1 reply
Sid

How can we get the query key on the server?

I have prefetched a query on the server, but I also want to use the value on the server

When I log the cache, I can see the result of the prefetch is there, I just can't find the key to access it by

The
getQueryKey
getQueryKey
function doesn't seem to work with the server API provided by
createHydrationHelpers
createHydrationHelpers

export default async function Page({
  params,
}: {
  params: Promise<{ ["project-slug"]: string; ["org-slug"]: string }>;
}) {
  const { ["project-slug"]: projectSlug, ["org-slug"]: orgSlug } = await params;

  await serverApi.client.project.get.prefetch({
    orgSlug,
    projectSlug,
  });

  console.log(getQueryKey(serverApi.client.project.get));

  return (
    <>
      <div>Project page</div>
      <div>{orgSlug}</div>
      <div>{projectSlug}</div>
    </>
  );
}
export default async function Page({
  params,
}: {
  params: Promise<{ ["project-slug"]: string; ["org-slug"]: string }>;
}) {
  const { ["project-slug"]: projectSlug, ["org-slug"]: orgSlug } = await params;

  await serverApi.client.project.get.prefetch({
    orgSlug,
    projectSlug,
  });

  console.log(getQueryKey(serverApi.client.project.get));

  return (
    <>
      <div>Project page</div>
      <div>{orgSlug}</div>
      <div>{projectSlug}</div>
    </>
  );
}
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

Get Query Key on Server
SebasPtschSSebasPtsch / ❓-help
3y ago
Where can I add a query key?
AliAAli / ❓-help
3y ago
Can we bundle WS TRPC Server?
AndrésAAndrés / ❓-help
13mo ago