{"record":{"id":"0fa1e1b8e48223bf","repo":"marmelab/react-admin","slug":"deletewithconfirmbutton-components-should-be-use","errorCode":null,"errorMessage":"<DeleteWithConfirmButton> components should be used inside a <Resource> component or provided with a resource prop. (The <Resource> component set the resource prop for all its children).","messagePattern":"<DeleteWithConfirmButton> components should be used inside a <Resource> component or provided with a resource prop\\. \\(The <Resource> component set the resource prop for all its children\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx","lineNumber":67,"sourceCode":"            translateOptions = {},\n            titleTranslateOptions = translateOptions,\n            contentTranslateOptions = translateOptions,\n            mutationOptions,\n            color = 'error',\n            successMessage,\n            ...rest\n        } = props;\n        const translate = useTranslate();\n        const record = useRecordContext(props);\n        const resource = useResourceContext(props);\n        const notify = useNotify();\n        const unselect = useUnselect(resource);\n        const redirect = useRedirect();\n        // null when the delete button is used outside a form (e.g. in a list)\n        const form = useFormContext();\n        const [open, setOpen] = React.useState(false);\n        if (!resource) {\n            throw new Error(\n                '<DeleteWithConfirmButton> components should be used inside a <Resource> component or provided with a resource prop. (The <Resource> component set the resource prop for all its children).'\n            );\n        }\n\n        const { onSuccess, onError, ...otherMutationOptions } =\n            mutationOptions || {};\n\n        const { isPending, handleDelete } = useDeleteController({\n            record,\n            redirect: redirectTo,\n            mutationMode,\n            mutationOptions: {\n                ...otherMutationOptions,\n                onSuccess: (...args) => {\n                    setOpen(false);\n                    if (onSuccess) {\n                        onSuccess(...args);\n                    } else {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx#L49-L85","documentation":"DeleteWithConfirmButton requires a resource context to build the delete mutation and redirect. The library throws this error when the button is rendered without a `resource` prop AND outside any <Resource> component that would set it via context. This prevents silent failures where the delete target resource is unknown.","triggerScenarios":"Rendering <DeleteWithConfirmButton> outside a <Resource> context (e.g. in a standalone page or custom layout) without passing a `resource` prop; useResourceContext(props) returns null.","commonSituations":"Using the button in a custom dashboard or dialog outside List/Edit/Show views; refactoring views out of a <Resource> tree and forgetting the prop; wrapping children in a component that breaks ResourceContext.","solutions":["Pass an explicit resource prop: <DeleteWithConfirmButton resource=\"posts\" />","Render the button inside a component tree wrapped by <ResourceContextProvider resource=\"posts\">","Move the button back inside a List/Edit/Show view where the Resource context is set"],"exampleFix":"// before\n<DeleteWithConfirmButton record={record} />\n// after\n<DeleteWithConfirmButton resource=\"posts\" record={record} />","handlingStrategy":"validation","validationCode":"const resource = props.resource ?? useResourceContextSafe();\nif (!resource) throw new Error('DeleteWithConfirmButton needs a resource prop or Resource context');","typeGuard":"const hasResource = (p: { resource?: string } & Record<string, unknown>): p is { resource: string } & typeof p => typeof p.resource === 'string' && p.resource.length > 0;","tryCatchPattern":null,"preventionTips":["Always pass an explicit resource prop when using action buttons outside List/Show/Edit views","Wrap standalone pages in ResourceContextProvider","Add a unit test rendering each button outside Resource context to catch regressions"],"tags":["react-admin","missing-prop","resource-context"],"backgroundTag":"missing-required-resource-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}