T
TanStack2y ago
genetic-orange

Guidance on passing hooks to router context?

I'm using hooks from Clerk to try to pass into the router context but not sure what the best approach is. I'm getting error `21:47:23.742 Cannot destructure property 'organization' of 'useRouteContext(...)' as it is undefined. occassionally. But this is where I landed, seems to work ok. but wasn't sure exactly what the best way of passing hooks in to the router instance's context. I feel like i've run into race conditions while working through this. so figured i'd ask.
interface MyRouterContext {
user: ReturnType<typeof useUser>
organization: ReturnType<typeof useOrganization>
trpc: typeof trpc
queryClient: typeof queryClient
}

export const rootRoute = rootRouteWithContext<MyRouterContext>()({
component: Root,
})

export const router = new Router({
routeTree,
context: {
organization: undefined!,
user: undefined!,
trpc: trpc,
queryClient: queryClient,
}, // inject this in app-providers.tsx
})
interface MyRouterContext {
user: ReturnType<typeof useUser>
organization: ReturnType<typeof useOrganization>
trpc: typeof trpc
queryClient: typeof queryClient
}

export const rootRoute = rootRouteWithContext<MyRouterContext>()({
component: Root,
})

export const router = new Router({
routeTree,
context: {
organization: undefined!,
user: undefined!,
trpc: trpc,
queryClient: queryClient,
}, // inject this in app-providers.tsx
})
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?