Next.js Discord

Discord Forum

how is this pattern for getting data from my database? and then displaying it in page.tsx?

Unanswered
Pacific sand lance posted this in #help-forum
Open in Discord
Original message was deleted.

4 Replies

Pacific sand lance
Something feels wrong but Im not sure. It works but im not sure if I am following best practices.
Pacific sand lance
import { prisma } from "~/lib/prisma";
 
export default async function Page() {
  const user = await prisma.user.findUnique({ where: { id: 123456 } });
  return <div>{user?.name}</div>;
}
i think that i should try to do something like this, but i thought that in react you have to store it in state to use it in the return.
and then storing it in state would make it a client component