Persistent layouts don't have access to usePage - how to resolve this? #789
Unanswered
arondeparon
asked this question in
Help (React)
Replies: 2 comments 1 reply
-
Have you tried putting use Page inside MyCustomAppComponent? |
Beta Was this translation helpful? Give feedback.
1 reply
-
You can access shared data in your layouts using the import { InertiaLink, usePage } from '@inertiajs/inertia-react'
export default function Layout({ children }) {
const { auth } = usePage().props
return (
<main>
<header>
<div>You are logged in as: {auth.user.name}</div>
<nav>
<InertiaLink href="/">Home</InertiaLink>
<InertiaLink href="/about">About</InertiaLink>
<InertiaLink href="/contact">Contact</InertiaLink>
</nav>
</header>
<content>{children}</content>
<footer></footer>
</main>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to figure out how I can use a custom app component so that I can inject some global logic into my application, while still being able to access the
usePage()
hook.I tried an approach like this:
This does work, but it prevents
MyApp
from accessingusePage()
, since we are not within theInertiaApp
component.Using a layout seems to make sense, but I cannot use a layout as a wrapping component if I want it to be persistent across page loads.
How can I fix this in a way that this does become possible?
Beta Was this translation helpful? Give feedback.
All reactions