marmelab/react-admin · error · Error

useShowController requires a non-empty resource prop or cont

Error message

useShowController requires a non-empty resource prop or context

What it means

useShowController (backing <Show>) needs a resource name to call dataProvider.getOne(). It resolves it from the `resource` prop or ResourceContext, and throws when neither provides a non-empty value.

Source

Thrown at packages/ra-core/src/controller/show/useShowController.ts:63

 *     const controllerProps = useShowController({ resource: 'posts', id: 1234 });
 *     return <ShowView {...controllerProps} />;
 * };
 */
export const useShowController = <
    RecordType extends RaRecord = any,
    ErrorType = Error,
>(
    props: ShowControllerProps<RecordType, ErrorType> = {}
): ShowControllerResult<RecordType, ErrorType> => {
    const {
        disableAuthentication = false,
        id: propsId,
        queryOptions = {},
        redirectOnError = DefaultRedirectOnError,
    } = props;
    const resource = useResourceContext(props);
    if (!resource) {
        throw new Error(
            `useShowController requires a non-empty resource prop or context`
        );
    }

    const { isPending: isPendingAuthenticated } = useAuthenticated({
        enabled: !disableAuthentication,
    });

    const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({
        action: 'show',
        resource,
        enabled: !disableAuthentication && !isPendingAuthenticated,
    });

    const getRecordRepresentation = useGetRecordRepresentation(resource);
    const translate = useTranslate();
    const notify = useNotify();
    const redirect = useRedirect();

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass resource explicitly: <Show resource="posts" id={123}>
  2. Render inside a <Resource name="posts"> route so the context supplies it
  3. Fix routing so :resource/:id params resolve
  4. Guard: return null or an error boundary when resource is falsy

Example fix

// before
const MyShow = () => <Show id={id} />;
// after
const MyShow = () => <Show resource="posts" id={id} />;
// or inside routes:
<Resource name="posts" show={MyShow} />
Defensive patterns

Strategy: validation

Validate before calling

const resource = props.resource ?? useResourceContext();
if (!resource) throw new Error('Show requires a resource');
return <Show resource={resource} id={id} />;

Type guard

const hasResource = (p: { resource?: string }): p is { resource: string } =>
  typeof p.resource === 'string' && p.resource.length > 0;

Try / catch

try { return <Show resource={maybeResource} id={id} />; } catch (e) { if (String(e).includes('non-empty resource')) { return <NotFound />; } }

Prevention

When it happens

Trigger: Rendering <Show> outside a <Resource> without a `resource` prop; dynamic route params missing so resource resolves to undefined; empty string resource.

Common situations: Custom show pages rendered standalone; tests/stories without ResourceContext; broken route definitions after renaming resources.

Related errors


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