I'm currently making a user profile page on my website. I have created a directory /user/[id], where I get the user id and based on that I display their profile details. Since there are different tabs on the profile page, I decided to create a layout.js file in the /user directory, in which I put the main components that will not change and the components that will appear when the tabs are clicked. But in these components I display user data, which I get and check in layout.js. Is there any way to pass them to the children element?
#Is it possible to pass in children element props?
9 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
hi @untold lion
you can create utility function e.g. getUser and put prisma logic in that func. and call that utility func. in both layout.tsx and page.tsx, nextjs will never send 2nd request to db via prisma in the same request life cycle
I'll try to do that. Thank you very much!
Of course what M Zeeshan said and
@untold lion keep in mind, that your getUser function then would run twice!
To prevent having duplicate calls to your DB, make sure you wrap your function in a react cache:
const getUser = cache(() => {
// your code
})
This will memorize the response and only execute your code in it once
Understood. Thank you
✅ Success!
This question has been marked as answered! If you have any other questions, feel free to create another post
Jump to answer
[Click here](#1331724457949007945 message)