Error with "use cache"
Unanswered
Sloth bear posted this in #help-forum
Sloth bearOP
I have a file with a
, even tho I do use
getMember
query call marked as import 'server-only'
and when I invoke it on page.tsx
I am gettingRoute "/[lang]/dashboard/members/[...form]": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it
, even tho I do use
Suspense
, and I followed the the changes [here](https://nextjs.org/docs/messages/next-prerender-missing-suspense) and I moved Clerk's currentUser
to the component level instead of in the getMember
db query call.// page.tsx
type PageParams = Promise<Record<'form', ['add' | 'new', string]>>;
export default async function Page(props: { params: PageParams }) {
return (
<Suspense fallback={<PageFormSkeleton />}>
<PageForm params={props.params} />
</Suspense>
);
}
const PageForm = async (props: { params: PageParams }) => {
const user = await currentUser();
if (!user) {
throw new Error('Unauthorized access');
}
const params = await props.params;
const memberId = params.form[1];
const member = await getMember(Number(memberId));
return <MemberForm member={member ?? undefined} />;
};
// dbquery
import 'server-only';
export const getMember = async (id: number): Promise<Member | null> => {
'use cache';
cacheTag('member', id.toString());
return prisma.member.findUnique({
where: {
id
}
});
};