useRequestContext hook provides access to a request-scoped context to share data across multiple React Server Components while running on the server. It's useful for writing plugins and third-party libraries.
Example codeAnchor link to section titled "Example code"
useRequestContext hook takes the following arguments:
||No||A string to encapsulate data so that it's not modified by other scopes.|
Return valueAnchor link to section titled "Return value"
useRequestContext hook returns an object that can be mutated to store data.
ConsiderationsAnchor link to section titled "Considerations"
- Consider using the
useRequestContexthook only where appropriate. Generally, you should pass props down to the components instead. Use it to cache data across multiple React rendering cycles, or to share data across components that are located in different tree branches.
useRequestContexthook is only available when running on the server in server components or client components during server-side rendering (SSR). The hook is never shared in the browser.