--- title: useOutletContext --- # useOutletContext [MODES: framework, data, declarative] ## Summary [Reference Documentation ↗](https://api.reactrouter.com/v7/functions/react_router.useOutletContext.html) Returns the parent route [``](../components/Outlet). Often parent routes manage state or other values you want shared with child routes. You can create your own [context provider](https://react.dev/learn/passing-data-deeply-with-context) if you like, but this is such a common situation that it's built-into [``](../components/Outlet). ```tsx // Parent route function Parent() { const [count, setCount] = React.useState(0); return ; } ``` ```tsx // Child route import { useOutletContext } from "react-router"; function Child() { const [count, setCount] = useOutletContext(); const increment = () => setCount((c) => c + 1); return ; } ``` If you're using TypeScript, we recommend the parent component provide a custom hook for accessing the context value. This makes it easier for consumers to get nice typings, control consumers, and know who's consuming the context value. Here's a more realistic example: ```tsx filename=src/routes/dashboard.tsx lines=[14,20] import { useState } from "react"; import { Outlet, useOutletContext } from "react-router"; import type { User } from "./types"; type ContextType = { user: User | null }; export default function Dashboard() { const [user, setUser] = useState(null); return (

Dashboard

); } export function useUser() { return useOutletContext(); } ``` ```tsx filename=src/routes/dashboard/messages.tsx lines=[1,4] import { useUser } from "../dashboard"; export default function DashboardMessages() { const { user } = useUser(); return (

Messages

Hello, {user.name}!

); } ``` ## Signature ```tsx function useOutletContext(): Context ``` ## Returns The context value passed to the parent [`Outlet`](../components/Outlet) component