{"record":{"id":"ba315c7be05873bd","repo":"honojs/hono","slug":"requestcontext-is-not-provided","errorCode":null,"errorMessage":"RequestContext is not provided.","messagePattern":"RequestContext is not provided\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/middleware/jsx-renderer/index.ts","lineNumber":160,"sourceCode":" * }\n *\n * app.get('/page/info', (c) => {\n *   return c.render(\n *     <div>\n *       You are accessing: <RequestUrlBadge />\n *     </div>\n *   )\n * })\n * ```\n */\nexport const useRequestContext = <\n  E extends Env = any,\n  P extends string = any,\n  I extends Input = {},\n>(): Context<E, P, I> => {\n  const c = useContext(RequestContext)\n  if (!c) {\n    throw new Error('RequestContext is not provided.')\n  }\n  return c\n}\n","sourceCodeStart":142,"sourceCodeEnd":164,"githubUrl":"https://github.com/honojs/hono/blob/e2740d5a1bd0b4254e517e3af8b60789284bc7bd/src/middleware/jsx-renderer/index.ts#L142-L164","documentation":"useRequestContext() relies on React's useContext to retrieve the per-request Context object; it only works inside components rendered by the jsxRenderer middleware, which provides RequestContext. Calling it outside that render tree (no provider above the component) yields undefined and this error is thrown.","triggerScenarios":"Calling useRequestContext() in a component rendered by React DOM (client-side), in a route handler outside JSX rendering, in a component rendered via JSX without the jsxRenderer middleware installed, or during SSR of a tree that jsxRenderer did not create.","commonSituations":"Sharing components between a Hono app and a Vite/Next client app; forgetting app.use(jsxRenderer(...)) before routes using JSX; testing components in isolation with react-testing-library without wrapping in the RequestContext provider; upgrading Hono and missing middleware ordering changes.","solutions":["Ensure the jsxRenderer middleware is applied (app.use(jsxRenderer())) before routes that render the component","Render the component through c.render(...) so RequestContext is provided","In tests, wrap the component with the RequestContext provider (pass a mock Context) instead of rendering bare","For code shared with client rendering, pass the Context explicitly via props rather than using the hook"],"exampleFix":"// before\napp.get('/page', (c) => c.html(<Layout />)) // no RequestContext\n// after\napp.use(jsxRenderer())\napp.get('/page', (c) => c.render(<Layout />))","handlingStrategy":"validation","validationCode":"const canUseRequestContext = (): boolean => {\n  // works only when rendered via jsxRenderer; guard shared components:\n  try { useRequestContext(); return true } catch { return false }\n}","typeGuard":null,"tryCatchPattern":"// inside shared components:\nlet c: Context | undefined\ntry { c = useRequestContext() } catch { /* rendered outside jsxRenderer; fall back to props */ }","preventionTips":["Always mount app.use(jsxRenderer(...)) before JSX routes","Use c.render() rather than c.html() for JSX templates","In unit tests, wrap components in the RequestContext provider with a mock Context","Prefer prop-drilling the Context in components shared with client-side React"],"tags":["jsx-renderer","react","context","middleware","ssr"],"backgroundTag":"react-context-not-provided","analyzedSha":"e2740d5a1bd0b4254e517e3af8b60789284bc7bd","analyzedAt":"2026-08-28T10:18:08.750Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}