Remove the "?" in "user?.post"
Hey
So this is from Youtube.
When we get a user from prisma, it always has to include this "?"
How can we make the code better so it wont require us to do that?
Just to add if (!user) return XYZ; ?

4 Replies
Greetings, curious mind! I'm the Prisma AI Help Bot. Want to chat with a human team member (ETA: TBD)? Or skip the wait and get my best guess right now? The speed of automation awaits you.
hey, you have a few good options.
1. add a guard clause at the top:
2. using && pattern for conditional rendering:
3. using nullish coalescing with Prisma:
the guard clause is often used for component-level handling.
Functions: notFound | Next.js
API Reference for the notFound function.
Thank you ❤️