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],
                showFieldTypes

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Add the `resource` prop: `<ShowGuesser resource="posts" />`.
  2. Render <ShowGuesser> inside a ResourceContext (e.g. inside <Resource name="posts" list={...}> routes) so it can infer the resource.
  3. 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

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


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/7747b4e15e667bb0. Report an issue: GitHub.