{"record":{"id":"664f73705fe09258","repo":"marmelab/react-admin","slug":"usedelete-mutation-requires-a-resource","errorCode":null,"errorMessage":"useDelete mutation requires a resource","messagePattern":"useDelete mutation requires a resource","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/dataProvider/useDelete.ts","lineNumber":104,"sourceCode":">(\n    resource?: string,\n    params: Partial<DeleteParams<RecordType>> = {},\n    options: UseDeleteOptions<RecordType, MutationError> = {}\n): UseDeleteResult<RecordType, MutationError> => {\n    const dataProvider = useDataProvider();\n    const queryClient = useQueryClient();\n    const {\n        mutationMode = 'pessimistic',\n        mutationFn: customMutationFn,\n        onSettled,\n        ...mutationOptions\n    } = options;\n    const customMutationFnWithDataProviderResult = async (\n        resource: string | undefined,\n        params: Omit<UseDeleteMutateParams<RecordType>, 'resource'>\n    ) => {\n        if (resource == null) {\n            throw new Error('useDelete mutation requires a resource');\n        }\n        if (params.id == null) {\n            throw new Error('useDelete mutation requires a non-empty id');\n        }\n        if (customMutationFn == null) {\n            return dataProvider.delete<RecordType>(\n                resource,\n                params as DeleteParams<RecordType>\n            );\n        }\n\n        return {\n            data: await customMutationFn({ resource, ...params }),\n        };\n    };\n\n    const [mutate, mutationResult] = useMutationWithMutationMode<\n        MutationError,","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/dataProvider/useDelete.ts#L86-L122","documentation":"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.","triggerScenarios":"Calling mutate() (or the DeleteWithConfirmButton flow) from useCreate-style usage where useDelete() was called with no argument outside a resource context.","commonSituations":"Custom delete buttons rendered outside Resource routes; refactored components losing the record/resource context prop.","solutions":["Pass resource explicitly: mutate('posts', { id: 123 })","Call useDelete('posts') with the resource argument","Ensure the component is inside a Resource/route so useResourceContext resolves the resource"],"exampleFix":"// before\nconst { mutate } = useDelete();\nmutate({ id: record.id });\n// after\nconst { mutate } = useDelete('posts');\nmutate('posts', { id: record.id });","handlingStrategy":"validation","validationCode":"const resource = resourceProp ?? resourceFromContext;\nif (resource == null) {\n  throw new Error('useDelete requires a resource');\n}","typeGuard":"const hasResource = (r: string | undefined | null): r is string => typeof r === 'string' && r.length > 0;","tryCatchPattern":"try {\n  await mutate('posts', { id });\n} catch (e) {\n  if (e.message === 'useDelete mutation requires a resource') {\n    notify('Cannot delete: no resource context', { type: 'warning' });\n    return;\n  }\n  throw e;\n}","preventionTips":["Pass resource explicitly to useDelete instead of relying on context","Render delete controls only within Resource-scoped pages","Thread resource as a typed required prop to custom button components"],"tags":["react-admin","usedelete","mutation","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}