marmelab/react-admin · error · Error

useCreateController requires a non-empty resource prop or co

Error message

useCreateController requires a non-empty resource prop or context

What it means

useCreateController builds the Create view controller and needs a resource name to know which data provider endpoint to call and how to build routes/redirections. It resolves the resource from the prop or ResourceContext via useResourceContext; if both are empty it throws this error.

Source

Thrown at packages/ra-core/src/controller/create/useCreateController.ts:59

>(
    props: CreateControllerProps<
        RecordType,
        MutationOptionsError,
        ResultRecordType
    > = {}
): CreateControllerResult<RecordType> => {
    const {
        disableAuthentication,
        record,
        redirect: redirectTo,
        transform,
        mutationMode = 'pessimistic',
        mutationOptions = {},
    } = props;

    const resource = useResourceContext(props);
    if (!resource) {
        throw new Error(
            'useCreateController requires a non-empty resource prop or context'
        );
    }
    const { isPending: isPendingAuthenticated } = useAuthenticated({
        enabled: !disableAuthentication,
    });
    const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({
        action: 'create',
        resource,
        enabled: !disableAuthentication && !isPendingAuthenticated,
    });
    const { hasEdit, hasShow } = useResourceDefinition(props);
    const finalRedirectTo =
        redirectTo ?? getDefaultRedirectRoute(hasShow, hasEdit);
    const translate = useTranslate();
    const notify = useNotify();
    const redirect = useRedirect();
    const { onSuccess, onError, meta, ...otherMutationOptions } =

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass a non-empty resource prop: `<Create resource="posts">` or `useCreateController({ resource: 'posts' })`.
  2. Render the component inside the matching <Resource name="posts"> so the context supplies the resource.
  3. Register the page as a child of <Resource> in <Admin> rather than as an arbitrary custom route.
  4. Check that you are not passing an empty string or undefined variable as resource (e.g. from a broken constant import).

Example fix

// before
const controller = useCreateController({});

// after
const controller = useCreateController({ resource: 'posts' });
Defensive patterns

Strategy: validation

Validate before calling

// Before rendering, ensure a resource is defined
const resource = props.resource ?? useResourceContext();
if (!resource) throw new Error('Create view rendered without a resource; pass resource="..."');

Type guard

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

Try / catch

// Render-time hook throws cannot be caught with try/catch inside the same
// component; use an error boundary or pre-validate:
if (!hasResource(props)) return <MissingResource resourceName={props.resource} />;
const controller = useCreateController(props);

Prevention

When it happens

Trigger: Rendering a <Create> component (or calling useCreateController directly) outside a <Resource> without a `resource` prop, or passing an empty-string resource prop.

Common situations: Building a custom create form displayed on a standalone route not registered under <Resource>; reusing Create in a modal outside the Admin router; forgetting the resource prop when wrapping useCreateController in a custom hook.

Related errors


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