marmelab/react-admin · error · Error

useUpdate mutation requires a resource

Error message

useUpdate mutation requires a resource

What it means

useUpdate wraps dataProvider.update; its mutate function takes the resource as the first argument. A null/undefined resource means the target resource is unknown, so the hook throws before touching the data provider.

Source

Thrown at packages/ra-core/src/dataProvider/useUpdate.ts:108

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

    const dataProviderUpdate = useEvent(
        (resource: string, params: UpdateParams<RecordType>) =>
            dataProvider.update<RecordType>(resource, params)
    );
    const customMutationFnWithDataProviderResult = async (
        resource: string | undefined,
        params: Omit<UseUpdateMutateParams<RecordType>, 'resource'>
    ) => {
        if (resource == null) {
            throw new Error('useUpdate mutation requires a resource');
        }
        if (params.id == null) {
            throw new Error('useUpdate mutation requires a non-empty id');
        }
        if (!params.data) {
            throw new Error(
                'useUpdate mutation requires a non-empty data object'
            );
        }
        if (customMutationFn == null) {
            return dataProviderUpdate(
                resource,
                params as UpdateParams<RecordType>
            );
        }

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

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass the resource string: mutate('posts', { id, data }).
  2. Use useResourceContext() and render only when it is defined.
  3. Add a fallback default resource for shared components.

Example fix

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

Strategy: validation

Validate before calling

if (typeof resource !== 'string' || resource.length === 0) {
  throw new TypeError('useUpdate: 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!, { id, data });
} catch (e) {
  if (e instanceof Error && e.message.includes('requires a resource')) {
    notify('Update failed: unknown resource', { type: 'warning' });
  } else throw e;
}

Prevention

When it happens

Trigger: Calling mutate(undefined, { id, data }); resource read from an undefined route param or missing context; invoking mutate in a component used outside a Resource.

Common situations: Custom edit toolbar reused outside an edit route; resource prop not forwarded to a deeply nested component; dynamic resource from URL that is undefined on the wrong page.

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