Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/router/framework/react/guide/router-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ export const Route = createFileRoute('/todos')({
})
```

You can use it in your components with the `useRouteContext` hook:

```tsx
import { createFileRoute, useRouteContext } from '@tanstack/react-router';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this import since you are using Route.useRouteContext


export const Route = createFileRoute('/todos')({ component: Todos });

function Todos() {
const routeContext = Route.useRouteContext();
return <div>Todos from {routeContext.user.id}</div>;
}
```

You can even inject data fetching and mutation implementations themselves! In fact, this is highly recommended 😜

Let's try this with a simple function to fetch some todos:
Expand Down