How to pass props up to Layout in App Router?
Unanswered
Schweizer Laufhund posted this in #help-forum
Schweizer LaufhundOP
So I have my RootLayout which contains a <Navbar> component that takes a "user" prop and isLogged prop. When a user logs in to my site, I want the navbar to change to display the username and some other data from this "user" prop.
However, my login page is a lower level component so how would I pass the props up to my RootLayout? Or is there some other way for me to go about this?
However, my login page is a lower level component so how would I pass the props up to my RootLayout? Or is there some other way for me to go about this?
6 Replies
@Schweizer Laufhund So I have my RootLayout which contains a <Navbar> component that takes a "user" prop and isLogged prop. When a user logs in to my site, I want the navbar to change to display the username and some other data from this "user" prop.
However, my login page is a lower level component so how would I pass the props up to my RootLayout? Or is there some other way for me to go about this?
hi, you could run a function directly inside
Navbar to check the auth state and use cache from react to wrap the function if its being called by multiple place in the same layout@Ray hi, you could run a function directly inside `Navbar` to check the auth state and use `cache` from react to wrap the function if its being called by multiple place in the same layout
Schweizer LaufhundOP
so like make a request to the backend in the navbar component to check for user authentication instead of having it be a prop?
also im not familiar with cache in react what would that do in this case
you can fetch whatever data you need in a server component