Skip to main content

RouterContextProvider

RouterContextProvider

Framework Data

Summary

Reference Documentation ↗

Provides methods for writing/reading values in application context in a type-safe way. Primarily for usage with middleware.

import {
  createContext,
  RouterContextProvider
} from "react-router";

const userContext = createContext<User | null>(null);
const contextProvider = new RouterContextProvider();
contextProvider.set(userContext, getUser());
//                               ^ Type-safe
const user = contextProvider.get(userContext);
//    ^ User
Translation © 2026 fanyi.dev · Original © 2026 React Training LLC, Remix Software Inc., Shopify Inc. (MIT)