{"record":{"id":"c5eb53c291750fc3","repo":"marmelab/react-admin","slug":"the-updatewithundobutton-must-be-used-inside-a-rec","errorCode":null,"errorMessage":"The UpdateWithUndoButton must be used inside a RecordContext.Provider or must be passed a record prop.","messagePattern":"The UpdateWithUndoButton must be used inside a RecordContext\\.Provider or must be passed a record prop\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/button/UpdateWithUndoButton.tsx","lineNumber":71,"sourceCode":"            ),\n        });\n        // We don't support React elements for this\n        if (React.isValidElement(recordRepresentation)) {\n            recordRepresentation = `#${record?.id}`;\n        }\n        const label = useResourceTranslation({\n            resourceI18nKey: `resources.${resource}.action.update`,\n            baseI18nKey: 'ra.action.update',\n            options: {\n                name: resourceName,\n                recordRepresentation,\n            },\n            userText: labelProp,\n        });\n\n        const handleClick = e => {\n            if (!record) {\n                throw new Error(\n                    'The UpdateWithUndoButton must be used inside a RecordContext.Provider or must be passed a record prop.'\n                );\n            }\n            handleUpdate(data);\n            if (typeof onClick === 'function') {\n                onClick(e);\n            }\n            e.stopPropagation();\n        };\n\n        return (\n            <StyledButton\n                ref={ref}\n                onClick={handleClick}\n                // avoid double translation\n                label={<>{label}</>}\n                // If users provide a ReactNode as label, its their responsibility to also provide an aria-label should they need it\n                aria-label={typeof label === 'string' ? label : undefined}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/UpdateWithUndoButton.tsx#L53-L89","documentation":"UpdateWithUndoButton performs an undo-able update on the current record; it must know which record to update. If no `record` prop was passed and no RecordContext.Provider supplies one, the click handler throws.","triggerScenarios":"Clicking <UpdateWithUndoButton> rendered outside a RecordContext.Provider without a `record` prop; record is undefined when handleClick fires.","commonSituations":"Buttons placed in headers or toolbars without record context; bulk-action rows where record wasn't forwarded; forgetting the prop in custom tables.","solutions":["Pass record explicitly: <UpdateWithUndoButton record={record} data={...} />","Render the button inside Edit/Show views where RecordContext is provided","Wrap usage in <RecordContext.Provider value={record}>"],"exampleFix":"// before\n<UpdateWithUndoButton data={{ is_published: true }} />\n// after\n<UpdateWithUndoButton record={record} data={{ is_published: true }} />","handlingStrategy":"validation","validationCode":"if (!record) {\n  // render button disabled or skip entirely\n  return null;\n}\nreturn <UpdateWithUndoButton record={record} data={data} />;","typeGuard":"const hasRecord = (r: RaRecord | undefined): r is RaRecord => r != null && typeof r === 'object' && 'id' in r;","tryCatchPattern":null,"preventionTips":["Only render UpdateWithUndoButton when a record is available","Guard with useRecordContext() and fall back to a disabled state","In custom tables, forward the row record explicitly to action props"],"tags":["react-admin","missing-record","record-context"],"backgroundTag":"missing-required-resource-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}