Skip to content
Open
Changes from 1 commit
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 { useRouteContext } from '@tanstack/react-router'

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

function Todos() {
const routeContext = useRouteContext({ from: Route.id });
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