Sid
Sid
TtRPC
Created by Sid on 1/18/2025 in #❓-help
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 function doesn't seem to work with the server API provided by 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>
</>
);
}
2 replies