marmelab/react-admin · error · Error

useUpdateMany mutation requires a resource

Error message

useUpdateMany mutation requires a resource

What it means

useUpdateMany wraps dataProvider.updateMany for bulk edits; its mutate takes the resource as the first argument. A null/undefined resource leaves the target collection unknown, so the hook throws before invoking the data provider.

Source

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

    const dataProvider = useDataProvider();
    const queryClient = useQueryClient();
    const {
        mutationMode = 'pessimistic',
        getMutateWithMiddlewares,
        mutationFn: customMutationFn,
        ...mutationOptions
    } = options;

    const dataProviderUpdateMany = useEvent(
        (resource: string, params: UpdateManyParams<RecordType>) =>
            dataProvider.updateMany<RecordType>(resource, params)
    );
    const customMutationFnWithDataProviderResult = async (
        resource: string | undefined,
        params: Omit<UseUpdateManyMutateParams<RecordType>, 'resource'>
    ) => {
        if (resource == null) {
            throw new Error('useUpdateMany mutation requires a resource');
        }
        if (params.ids == null) {
            throw new Error('useUpdateMany mutation requires an array of ids');
        }
        if (!params.data) {
            throw new Error(
                'useUpdateMany mutation requires a non-empty data object'
            );
        }
        if (customMutationFn == null) {
            return dataProviderUpdateMany(
                resource,
                params as UpdateManyParams<RecordType>
            );
        }

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

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass the resource string: mutate('posts', { ids, data }).
  2. Use useResourceContext() and gate rendering on it being defined.
  3. Forward the resource prop explicitly into bulk-edit dialogs.

Example fix

// before
updateMany(resource, { ids, data }); // resource undefined
// after
const resource = useResourceContext();
if (!resource) return;
updateMany(resource, { ids, data });
Defensive patterns

Strategy: validation

Validate before calling

if (typeof resource !== 'string' || resource.length === 0) {
  throw new TypeError('useUpdateMany: resource must be a non-empty string');
}

Type guard

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

Try / catch

try {
  await mutate(resource!, { ids, data });
} catch (e) {
  if (e instanceof Error && e.message.includes('requires a resource')) {
    notify('Bulk update failed: unknown resource', { type: 'warning' });
  } else throw e;
}

Prevention

When it happens

Trigger: Calling mutate(undefined, { ids, data }); resource from an undefined route param; bulk-edit dialog rendered outside a Resource context so useResourceContext returns undefined.

Common situations: Bulk-edit modals reused across pages without passing the resource; refactors that removed a resource prop; dynamic resources resolved from URL that are absent on the current route.

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/c090665332bc2491. Report an issue: GitHub.