T
TanStack7mo ago
wise-white

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
eastern-cyan
eastern-cyan7mo ago
you would need to use from: rootRouteId that's exported by react-router
wise-white
wise-whiteOP7mo ago
Thanks a lot

Did you find this page helpful?