RuntimeContext
RuntimeContext is a React Context used to get Runtime context information in components. This Context can be accessed through React's use or useContext API.
The useRuntimeContext Hook has been deprecated. Please use use(RuntimeContext) instead. useRuntimeContext is internally implemented as useContext(RuntimeContext), while use(RuntimeContext) is the recommended new approach in React 19.
Usage
Type Definition
Property Description
isBrowser: Indicates whether the current runtime environment is a browserroutes: Route configuration informationrequestContext: Request context, containingrequestandresponseobjectscontext: Deprecated, please userequestContextinstead
RequestContext
RequestContext is the type of the requestContext property, containing request and response related information:
Notes:
response.setHeaderandresponse.statusare only available on the server-side (SSR)- On the browser side, the
responseobject may not contain these methods - The
requestobject is available on both server and browser, but server-side information is more complete
Usage Examples
Distinguishing Runtime Environment
Getting Request Context
When SSR is enabled, isomorphic request context can be obtained in both Node environment and browser environment.
The slight difference is that the Node environment also supports setting response headers, response codes, and provides Logger logging and Metrics tracking.
When SSR is not enabled, only the information that can be obtained on the browser side is included.
Accessing Injected Global Data
Global data can be injected into RuntimeContext through the onBeforeRender hook of Runtime plugins: