Skip to main content

useOutletContext

Returns the context value passed to the parent route’s <Outlet> component.

Return Value

unknown
The context value passed to the parent <Outlet> component. The type is unknown by default but can be typed using TypeScript generics.

Type Declaration

Usage Examples

Basic Usage

Sharing State Between Parent and Child Routes

TypeScript Usage with Custom Hook

Passing Multiple Values

Common Patterns

Authentication Context

Form Context

API Client Context

Type Safety Best Practices

Export Custom Hook from Parent

Using satisfies for Type Safety

Notes

  • The context is unknown by default - use TypeScript generics for type safety
  • Context is only available to direct child routes rendered by the <Outlet>
  • Prefer creating custom hooks that wrap useOutletContext for better type safety
  • Context is passed down only one level - nested outlets need to pass context again
  • This is often a better alternative to React Context API for route-specific state