marmelab/react-admin · error
<ShowGuesser> was called outside of a ResourceContext and wi
Error message
<ShowGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.
What it means
<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.
Source
Thrown at packages/ra-ui-materialui/src/detail/ShowGuesser.tsx:33
export const ShowGuesser = ({
id,
queryOptions,
resource,
...rest
}: Omit<ShowProps, 'children'> & { enableLog?: boolean }) => (
<ShowBase id={id} resource={resource} queryOptions={queryOptions}>
<ShowGuesserView {...rest} />
</ShowBase>
);
export const ShowGuesserView = (
props: Omit<ShowProps, 'children'> & { enableLog?: boolean }
) => {
const resource = useResourceContext(props);
if (!resource) {
throw new Error(
`<ShowGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`
);
}
const { record } = useShowContext();
const [child, setChild] = useState<ReactNode>(null);
const { enableLog = process.env.NODE_ENV === 'development', ...rest } =
props;
useEffect(() => {
setChild(null);
}, [resource]);
useEffect(() => {
if (record && !child) {
const inferredElements = getElementsFromRecords(
[record],
showFieldTypesView on GitHub (pinned to 051f511bb0)
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.
Example fix
// before <ShowGuesser /> // after <ShowGuesser resource="posts" />
Defensive patterns
Strategy: validation
Validate before calling
const resource = props.resource ?? useContext(ResourceContext);
if (!resource) throw new Error('ShowGuesser requires resource prop or ResourceContext'); Prevention
- Render ShowGuesser only inside <Resource> routes or wrap it in ResourceContextProvider.
- Add explicit resource prop when using it in custom pages/tests.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- useCanAccess must be used inside a <Resource> component or p
- useCreateController requires a non-empty resource prop or co
- useEditController requires a non-empty resource prop or cont
- SimpleFormIteratorItem must be used in a ResourceContextProv
- DataTableRow can only be used within a RecordContext or be p
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/7747b4e15e667bb0.
Report an issue: GitHub.