{"record":{"id":"7747b4e15e667bb0","repo":"marmelab/react-admin","slug":"showguesser-was-called-outside-of-a-resourcecont","errorCode":null,"errorMessage":"<ShowGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.","messagePattern":"<ShowGuesser> was called outside of a ResourceContext and without a resource prop\\. You must set the resource prop\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/detail/ShowGuesser.tsx","lineNumber":33,"sourceCode":"\nexport const ShowGuesser = ({\n    id,\n    queryOptions,\n    resource,\n    ...rest\n}: Omit<ShowProps, 'children'> & { enableLog?: boolean }) => (\n    <ShowBase id={id} resource={resource} queryOptions={queryOptions}>\n        <ShowGuesserView {...rest} />\n    </ShowBase>\n);\n\nexport const ShowGuesserView = (\n    props: Omit<ShowProps, 'children'> & { enableLog?: boolean }\n) => {\n    const resource = useResourceContext(props);\n\n    if (!resource) {\n        throw new Error(\n            `<ShowGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`\n        );\n    }\n\n    const { record } = useShowContext();\n    const [child, setChild] = useState<ReactNode>(null);\n    const { enableLog = process.env.NODE_ENV === 'development', ...rest } =\n        props;\n\n    useEffect(() => {\n        setChild(null);\n    }, [resource]);\n\n    useEffect(() => {\n        if (record && !child) {\n            const inferredElements = getElementsFromRecords(\n                [record],\n                showFieldTypes","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/detail/ShowGuesser.tsx#L15-L51","documentation":"<ShowGuesser> determines which fields to display from the record's data; to do that it must know which resource it is showing. It reads the resource from ResourceContext (provided by routes inside <Resource>) or from an explicit `resource` prop; if both are absent it throws because inference is impossible.","triggerScenarios":"Rendering <ShowGuesserView>/<ShowGuesser> outside a <Resource> route context (e.g. in a custom page, storybook, or test) and without a `resource` prop; calling it in isolation where useResourceContext(props) returns undefined.","commonSituations":"Custom layouts that render ShowGuesser directly instead of via the resource routes; tests rendering <ShowGuesser> standalone; moving a view outside the <Resource> tree; typo in resource prop name.","solutions":["Add the `resource` prop: `<ShowGuesser resource=\"posts\" />`.","Render <ShowGuesser> inside a ResourceContext (e.g. inside <Resource name=\"posts\" list={...}> routes) so it can infer the resource.","Wrap with <ResourceContextProvider value=\"posts\"> if rendering outside normal routes."],"exampleFix":"// before\n<ShowGuesser />\n\n// after\n<ShowGuesser resource=\"posts\" />","handlingStrategy":"validation","validationCode":"const resource = props.resource ?? useContext(ResourceContext);\nif (!resource) throw new Error('ShowGuesser requires resource prop or ResourceContext');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Render ShowGuesser only inside <Resource> routes or wrap it in ResourceContextProvider.","Add explicit resource prop when using it in custom pages/tests."],"tags":["react-admin","showguesser","missing-context","resource"],"backgroundTag":"missing-context-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}