{"record":{"id":"54d04a7dbb11ed1d","repo":"marmelab/react-admin","slug":"listbutton-components-should-be-used-inside-a-r","errorCode":null,"errorMessage":"<ListButton> components should be used inside a <Resource> component or provided the resource prop.","messagePattern":"<ListButton> 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/ListButton.tsx","lineNumber":63,"sourceCode":"export const ListButton = React.forwardRef(function ListButton(\n    inProps: ListButtonProps,\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        resource: resourceProp,\n        scrollToTop = true,\n        ...rest\n    } = props;\n    const resource = useResourceContext(props);\n    if (!resource) {\n        throw new Error(\n            '<ListButton> components should be used inside a <Resource> component or provided the resource prop.'\n        );\n    }\n    const { canAccess, isPending } = useCanAccess({\n        action: 'list',\n        resource,\n    });\n    const createPath = useCreatePath();\n    const getResourceLabel = useGetResourceLabel();\n    const label = useResourceTranslation({\n        resourceI18nKey: `resources.${resource}.action.list`,\n        baseI18nKey: 'ra.action.list',\n        options: {\n            name: getResourceLabel(resource, 1),\n        },\n        userText: labelProp,\n    });\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/button/ListButton.tsx#L45-L81","documentation":"ListButton navigates to the list view of a resource, so the resource name must be resolvable. The library throws when no `resource` prop is given and no ResourceContext is present.","triggerScenarios":"Rendering <ListButton> with no resource prop outside any <Resource> / ResourceContextProvider; useResourceContext(props) returns null.","commonSituations":"Show/Edit action toolbars rendered in isolation; custom pages; refactored components losing context.","solutions":["Pass resource explicitly: <ListButton resource=\"posts\" />","Wrap usage in <ResourceContextProvider resource=\"posts\">","Render inside a standard Show/Edit view"],"exampleFix":"// before\n<ListButton />\n// after\n<ListButton resource=\"posts\" />","handlingStrategy":"validation","validationCode":"if (!resourceProp && !resourceContextValue) {\n  throw new Error('ListButton requires resource prop or ResourceContext');\n}","typeGuard":"const resolveResource = (r?: string): string | null => (typeof r === 'string' && r ? r : null);","tryCatchPattern":null,"preventionTips":["Use ListButton only within Show/Edit toolbars under a Resource","Pass resource explicitly in reusable toolbars","Add Storybook tests rendering buttons without context to surface the issue early"],"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"}