-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Describe the bug
It seems that in release 1.28.2 the behavior of useRouteContext or beforeLoad has changed.
I return a context-change from beforeLoad, but the useRouteContext-hook return undefined in the component.
export const Route = createFileRoute('/')({
beforeLoad: () => ({ user: 'Armin' }),
component: HomeComponent,
});
function HomeComponent() {
console.log('render HomeComponent');
const ctx = Route.useRouteContext(); // ctx is undefined
console.log(ctx);
return (
<div className="p-2">
<h3>Welcome Home! {ctx.user}</h3> // this fails!!! if I change it to ctx?.user the user-name appears, but only after joining the route again
</div>
);
}Your Example Website or App
https://stackblitz.com/edit/tanstack-router-cfgel4?file=src%2Froutes%2Findex.tsx
Steps to Reproduce the Bug or Issue
If you go to Home, you'll see an error:
can't access property "user", ctx is undefinedIf I change the code to ctx?.user, the context is returned and the user-name appears, but only after joining the route again.
Expected behavior
The context should not be undefined.
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Firefox
- Version: 126.0b1
Additional context
Question in discord: https://discord.com/channels/719702312431386674/1230086872672239627
Metadata
Metadata
Assignees
Labels
No labels