Skip to content

React Router: ReactRouterContext

Functions, types, and exports for React Router: ReactRouterContext.

Page outline

The request context a route module receives in its loader, action, or middleware.

import type { ReactRouterContext } from "@palamedes/react-router"

type ReactRouterContext = Readonly<RouterContextProvider>;

constructor

Create a new RouterContextProvider instance

constructor(init?: Map<RouterContext, unknown>)

Parameters

NameTypeRequiredDescription
initMap<RouterContext, unknown>NoAn optional initial context map to populate the provider with

get

Access a value from the context. If no value has been set for the context, it will return the context's defaultValue if provided, or throw an error if no defaultValue was set.

get<T>(context: RouterContext<T>): T

Parameters

NameTypeRequiredDescription
contextRouterContext<T>YesThe context to get the value for

Returns

T

The value for the context, or the context's defaultValue if no value was set

set

Set a value for the context. If the context already has a value set, this will overwrite it.

set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void

Parameters

NameTypeRequiredDescription
contextCYesThe context to set the value for
valueC extends RouterContext<infer T> ? T : neverYesThe value to set for the context

Returns

void

{void}

Source entry on GitHub

Last updated: November 1, 2026