{"record":{"id":"7ec462e2018c3d86","repo":"marmelab/react-admin","slug":"showbutton-components-should-be-used-inside-a-r","errorCode":null,"errorMessage":"<ShowButton> components should be used inside a <Resource> component or provided the resource prop.","messagePattern":"<ShowButton> components should be used inside a <Resource> component or provided the resource prop\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/button/ShowButton.tsx","lineNumber":57,"sourceCode":"    inProps: ShowButtonProps<RecordType>,\n    ref: React.ForwardedRef<HTMLAnchorElement>\n) {\n    const props = useThemeProps({\n        props: inProps,\n        name: PREFIX,\n    });\n\n    const {\n        icon = defaultIcon,\n        label: labelProp,\n        record: recordProp,\n        resource: resourceProp,\n        scrollToTop = true,\n        ...rest\n    } = props;\n    const resource = useResourceContext(props);\n    if (!resource) {\n        throw new Error(\n            '<ShowButton> components should be used inside a <Resource> component or provided the resource prop.'\n        );\n    }\n    const record = useRecordContext(props);\n    const createPath = useCreatePath();\n    const { canAccess, isPending } = useCanAccess({\n        action: 'show',\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":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/ShowButton.tsx#L39-L75","documentation":"ShowButton links to the show view of a record and must know the target resource. The library throws at render time when no `resource` prop is supplied and no ResourceContext is available.","triggerScenarios":"Rendering <ShowButton> without a `resource` prop outside a <Resource> / ResourceContextProvider tree.","commonSituations":"Custom row actions in non-react-admin tables; buttons extracted into shared component libraries; pages rendered outside the Admin resources tree.","solutions":["Pass resource explicitly: <ShowButton resource=\"posts\" />","Wrap usage in <ResourceContextProvider resource=\"posts\">","Render inside a List/Edit view where the context exists"],"exampleFix":"// before\n<ShowButton />\n// after\n<ShowButton resource=\"posts\" />","handlingStrategy":"validation","validationCode":"const resource = props.resource ?? useContext(ResourceContext);\nif (!resource) {\n  throw new Error('ShowButton requires resource prop or ResourceContext');\n}","typeGuard":"const hasResource = (p: { resource?: string }): p is { resource: string } => !!p.resource;","tryCatchPattern":null,"preventionTips":["Wrap custom pages in ResourceContextProvider","Require resource in shared action-button component props","Verify buttons render correctly inside each standard view"],"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"}