marmelab/react-admin · error · Error

useDelete mutation requires a resource

Error message

useDelete mutation requires a resource

What it means

useDelete's mutation function requires a resource string before it can call dataProvider.delete. When the hook is used without a resource and none is resolvable from context, this error is thrown at mutate time.

Source

Thrown at packages/ra-core/src/dataProvider/useDelete.ts:104

>(
    resource?: string,
    params: Partial<DeleteParams<RecordType>> = {},
    options: UseDeleteOptions<RecordType, MutationError> = {}
): UseDeleteResult<RecordType, MutationError> => {
    const dataProvider = useDataProvider();
    const queryClient = useQueryClient();
    const {
        mutationMode = 'pessimistic',
        mutationFn: customMutationFn,
        onSettled,
        ...mutationOptions
    } = options;
    const customMutationFnWithDataProviderResult = async (
        resource: string | undefined,
        params: Omit<UseDeleteMutateParams<RecordType>, 'resource'>
    ) => {
        if (resource == null) {
            throw new Error('useDelete mutation requires a resource');
        }
        if (params.id == null) {
            throw new Error('useDelete mutation requires a non-empty id');
        }
        if (customMutationFn == null) {
            return dataProvider.delete<RecordType>(
                resource,
                params as DeleteParams<RecordType>
            );
        }

        return {
            data: await customMutationFn({ resource, ...params }),
        };
    };

    const [mutate, mutationResult] = useMutationWithMutationMode<
        MutationError,

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass resource explicitly: mutate('posts', { id: 123 })
  2. Call useDelete('posts') with the resource argument
  3. Ensure the component is inside a Resource/route so useResourceContext resolves the resource

Example fix

// before
const { mutate } = useDelete();
mutate({ id: record.id });
// after
const { mutate } = useDelete('posts');
mutate('posts', { id: record.id });
Defensive patterns

Strategy: validation

Validate before calling

const resource = resourceProp ?? resourceFromContext;
if (resource == null) {
  throw new Error('useDelete requires a resource');
}

Type guard

const hasResource = (r: string | undefined | null): r is string => typeof r === 'string' && r.length > 0;

Try / catch

try {
  await mutate('posts', { id });
} catch (e) {
  if (e.message === 'useDelete mutation requires a resource') {
    notify('Cannot delete: no resource context', { type: 'warning' });
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling mutate() (or the DeleteWithConfirmButton flow) from useCreate-style usage where useDelete() was called with no argument outside a resource context.

Common situations: Custom delete buttons rendered outside Resource routes; refactored components losing the record/resource context prop.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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