Sid
Sid3w ago

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>
</>
);
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?