loaderData
so I managed to get my route loader to work
but the subbed object is undefined
loader triggers and gets the data.
Isn't that the correct way to access the loaded data with
const subbed = Route.useLoaderData();
or const subbed = useLoaderData({from: "/subscription"})
?
12 Replies
like-gold•2y ago
Are you using react-query?
If so, you need to:
and
robust-apricotOP•2y ago
I have to pass the queryClient in the context in the root route for that to work right ?
I'm using clerk for auth and have to wait for that response - that I have already in the context
like-gold•2y ago
That means, you aren't using react-query for the data fetching.
Then,
and
robust-apricotOP•2y ago
I'm using tan stack query but it's my first time using tsq so yeah let me try that simpler getuserData - I missed that return function !
like-gold•2y ago
Yeah, its a matter of where the actual data fetching is happening. If you are using Tanstack Query then you need to follow those conventions, if not if is just a fetch then you can return it from the loader.
like-gold•2y ago
See the Basic + React Query (file-based) example.
https://stackblitz.com/github/tanstack/router/tree/main/examples/react/basic-react-query-file-based
StackBlitz
Router Basic React Query File Based Example - StackBlitz
Run official live example code for Router Basic React Query File Based, created by Tanstack on StackBlitz
robust-apricotOP•2y ago
allright. thx for your help. have you seen I added another fix for the documentation of rect router in the router chat
like-gold•2y ago
Could you link that here?
robust-apricotOP•2y ago
https://tanstack.com/router/v1/docs/framework/react/guide/router-context
// src/routes/todos.tsx
export const Route = createFileRoute('/todos')({
component: Todos,
loader: ({ context }) => {
await context.queryClient.ensureQueryData({
queryKey: ['todos', { userId: user.id }],
queryFn: fetchTodos,
})
},
})
is the example with loader and context
shouldn't that be
loader: async ({ context }) => {
because await later ?
@Sean Cassiere
async missing
like-gold•2y ago
Yup you are right.
robust-apricotOP•2y ago
I know 🙂
lol
like-gold•2y ago
I don't have merge access, so when I get up in the morning I'll ping Tanner or Manuel on that.