{"record":{"id":"880ddf5b70c63eb9","repo":"marmelab/react-admin","slug":"useshowcontext-must-be-used-inside-a-showcontextpr","errorCode":null,"errorMessage":"useShowContext must be used inside a ShowContextProvider","messagePattern":"useShowContext must be used inside a ShowContextProvider","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/show/useShowContext.tsx","lineNumber":23,"sourceCode":"import { ShowControllerResult } from './useShowController';\n\n/**\n * Hook to read the show controller props from the ShowContext.\n *\n * Used within a <ShowContextProvider> (e.g. as a descendent of <Show>).\n *\n * @returns {ShowControllerResult} create controller props\n *\n * @see useShowController for how it is filled\n */\nexport const useShowContext = <\n    RecordType extends RaRecord = any,\n    ErrorType = Error,\n>(): ShowControllerResult<RecordType, ErrorType> => {\n    const context = useContext(ShowContext);\n    // Props take precedence over the context\n    if (!context) {\n        throw new Error(\n            'useShowContext must be used inside a ShowContextProvider'\n        );\n    }\n    return context as ShowControllerResult<RecordType, ErrorType>;\n};\n","sourceCodeStart":5,"sourceCodeEnd":29,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/show/useShowContext.tsx#L5-L29","documentation":"useShowContext returns the ShowControllerResult (record, loaded state, etc.) from the ShowContext, which is provided by <ShowContextProvider> (used internally by <Show> and <ShowBase>). The error is thrown when the hook runs with no ShowContext above it, meaning the component is not inside a show view.","triggerScenarios":"Calling useShowContext() in a component rendered outside a Show/ShowBase tree: standalone pages, list views, custom routes, or tests without a ShowContextProvider wrapper. Note ShowBase itself consumes the controller internally — hooks like this only work in children of a provider.","commonSituations":"Moving a record-detail child component out of <Show> to be reused elsewhere; rendering the component in a portal-based modal rooted in another context-free tree; unit tests with renderHook lacking the provider; using useShowContext where useRecord or useGetOne was intended.","solutions":["Render the component inside <Show> or <ShowBase> so ShowContextProvider is present","If no show view exists, use useRecord() or useGetOne() instead","In tests, wrap: <ShowContextProvider value={mockControllerResult}>...</ShowContextProvider>"],"exampleFix":"// before\nexport const Title = () => { const c = useShowContext(); ... } // rendered outside Show\n// after\n<Show resource=\"posts\"><PostTitle /></Show> // hook now inside ShowContextProvider","handlingStrategy":"fallback","validationCode":null,"typeGuard":"const useMaybeShowContext = () => useContext(ShowContext); // returns undefined outside provider; check before narrowing","tryCatchPattern":null,"preventionTips":["Only use useShowContext in components rendered inside <Show>/<ShowBase>","Use useRecord() or useGetOne() when no show view is present","In tests, wrap components with ShowContextProvider and a mocked controller result"],"tags":["react-admin","react-context","hooks","provider-missing"],"backgroundTag":"hook-used-outside-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}