#Is it possible to pass in children element props?

9 messages · Page 1 of 1 (latest)

untold lion
#

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?

shell grottoBOT
#

🔎 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)

urban flame
#

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

untold lion
wheat sequoia
#

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

shell grottoBOT
wheat sequoia
#

happy to help