T
TanStack9mo ago
stormy-gold

Get root context anywhere in the code

so in my __root.tsx file, i write to the root context :' beforeLoad: async () => { const session = await getServerSession(); return { session }; },`` is there a way to get that context anywhere in the code, in nested components? I triend const context = useRouteContext({ from: '/' }); but on nested root it does not work, i get the error: Invariant failed: Could not find an active match from "/"`
2 Replies
optimistic-gold
optimistic-gold9mo ago
you would need to use from: rootRouteId that's exported by react-router
stormy-gold
stormy-goldOP9mo ago
Thanks a lot

Did you find this page helpful?