{"record":{"id":"f44d9ec8f3bb25d6","repo":"marmelab/react-admin","slug":"editbutton-components-should-be-used-inside-a-r","errorCode":null,"errorMessage":"<EditButton> 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":"<EditButton> 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/EditButton.tsx","lineNumber":55,"sourceCode":"    RecordType extends RaRecord = any,\n>(\n    inProps: EditButtonProps<RecordType>,\n    ref: React.ForwardedRef<HTMLAnchorElement>\n) {\n    const props = useThemeProps({\n        props: inProps,\n        name: PREFIX,\n    });\n    const {\n        icon = defaultIcon,\n        label: labelProp,\n        scrollToTop = true,\n        className,\n        ...rest\n    } = props;\n    const resource = useResourceContext(props);\n    if (!resource) {\n        throw new Error(\n            '<EditButton> 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 record = useRecordContext(props);\n    const createPath = useCreatePath();\n    const { canAccess, isPending } = useCanAccess({\n        action: 'edit',\n        resource,\n        record,\n    });\n    const getResourceLabel = useGetResourceLabel();\n    const getRecordRepresentation = useGetRecordRepresentation();\n    const recordRepresentationValue = getRecordRepresentation(record);\n\n    const recordRepresentation =\n        typeof recordRepresentationValue === 'string'\n            ? recordRepresentationValue\n            : recordRepresentationValue?.toString();","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/EditButton.tsx#L37-L73","documentation":"EditButton builds a navigation link to the edit view of a resource; it needs to know the resource name. The library throws at render time when neither a `resource` prop nor a ResourceContext provides one, since the edit path cannot be constructed.","triggerScenarios":"Rendering <EditButton> outside <Resource> without a `resource` prop; useResourceContext(props) resolves to null.","commonSituations":"Row action buttons reused in custom tables not wrapped in Resource context; dashboard widgets; forgetting the prop when abstracting actions into a shared component.","solutions":["Pass resource explicitly: <EditButton resource=\"posts\" />","Wrap usage in <ResourceContextProvider resource=\"posts\">","Use the button inside a Datagrid in a List view where context is set"],"exampleFix":"// before\n<EditButton />\n// after\n<EditButton resource=\"posts\" />","handlingStrategy":"validation","validationCode":"const resource = props.resource ?? getContextResource();\nif (!resource) {\n  console.error('EditButton rendered without resource; add resource prop');\n  return null;\n}","typeGuard":"function assertResource(r: string | undefined): asserts r is string { if (!r) throw new Error('missing resource'); }","tryCatchPattern":null,"preventionTips":["Keep navigation buttons inside Resource-provided trees","Define shared action components that require the resource prop","Test custom pages that embed row actions"],"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"}