{"record":{"id":"7b74a622f55618ec","repo":"marmelab/react-admin","slug":"deletewithundobutton-components-should-be-used-i","errorCode":null,"errorMessage":"<DeleteWithUndoButton> 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":"<DeleteWithUndoButton> 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/DeleteWithUndoButton.tsx","lineNumber":49,"sourceCode":"            name: PREFIX,\n        });\n\n        const {\n            label: labelProp,\n            className,\n            icon = defaultIcon,\n            onClick,\n            redirect = 'list',\n            mutationOptions,\n            color = 'error',\n            successMessage,\n            ...rest\n        } = props;\n\n        const record = useRecordContext(props);\n        const resource = useResourceContext(props);\n        if (!resource) {\n            throw new Error(\n                '<DeleteWithUndoButton> 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        const { isPending, handleDelete } = useDeleteController({\n            record,\n            resource,\n            redirect,\n            mutationMode: 'undoable',\n            mutationOptions,\n            successMessage,\n        });\n        const handleClick: ReactEventHandler<any> = event => {\n            event.stopPropagation();\n            handleDelete();\n            if (onClick) {\n                onClick(event);\n            }\n        };","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/DeleteWithUndoButton.tsx#L31-L67","documentation":"DeleteWithUndoButton determines which resource's record to delete from the resource context or a resource prop. If neither yields a resource, the library throws immediately during render because an undo-able delete cannot be dispatched without it.","triggerScenarios":"Rendering <DeleteWithUndoButton> with no `resource` prop and no enclosing <Resource> / ResourceContextProvider; useResourceContext(props) returns undefined.","commonSituations":"Custom toolbars outside Resource context; copy-pasting the button into a standalone component; forgetting the prop after moving a view outside <Resource>.","solutions":["Add the resource prop: <DeleteWithUndoButton resource=\"posts\" />","Wrap the usage in <ResourceContextProvider resource=\"posts\">","Render it inside a standard List/Edit/Show view"],"exampleFix":"// before\n<DeleteWithUndoButton />\n// after\n<DeleteWithUndoButton resource=\"posts\" />","handlingStrategy":"validation","validationCode":"if (!props.resource && !resourceContext) {\n  throw new Error('DeleteWithUndoButton requires a resource prop or Resource context');\n}","typeGuard":"const isResourceKnown = (r: string | undefined): r is string => typeof r === 'string' && r.length > 0;","tryCatchPattern":null,"preventionTips":["Prefer rendering undo-able action buttons inside standard views where context exists","Type button wrapper props with a required `resource: ResourceName` field","Lint custom toolbars for buttons lacking resource props"],"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"}