{"record":{"id":"3d9503c7e3878a68","repo":"marmelab/react-admin","slug":"datagridrow-can-only-be-used-within-a-resourcecont","errorCode":null,"errorMessage":"DatagridRow can only be used within a ResourceContext or be passed a resource prop","messagePattern":"DatagridRow can only be used within a ResourceContext or be passed a resource prop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx","lineNumber":75,"sourceCode":"    } = props;\n\n    if (typeof id === 'undefined') {\n        throw new Error('DatagridRow expects an id prop');\n    }\n    const context = useDatagridContext();\n    const translate = useTranslate();\n    const record = useRecordContext(props);\n    if (!record) {\n        throw new Error(\n            'DatagridRow can only be used within a RecordContext or be passed a record prop'\n        );\n    }\n    const resource = useResourceContext(props);\n    const resourceDefinition = useResourceDefinition(props);\n    const hasDetailView =\n        resourceDefinition.hasShow || resourceDefinition.hasEdit;\n    if (!resource) {\n        throw new Error(\n            'DatagridRow can only be used within a ResourceContext or be passed a resource prop'\n        );\n    }\n    const expandable =\n        (!context ||\n            !context.isRowExpandable ||\n            context.isRowExpandable(record)) &&\n        expand;\n    const [expanded, toggleExpanded] = useExpanded(\n        resource,\n        id,\n        context && context.expandSingle\n    );\n    const [nbColumns, setNbColumns] = useState(() =>\n        computeNbColumns(expandable, children, hasBulkActions)\n    );\n    useEffect(() => {\n        // Fields can be hidden dynamically based on permissions;","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx#L57-L93","documentation":"DatagridRow resolves the resource name via useResourceContext(props) and uses useResourceDefinition to decide whether rows link to show/edit views. When no resource exists in context and none was passed as a prop, it throws because it cannot compute hasDetailView or build row routes.","triggerScenarios":"Rendering <DatagridRow> (or a custom row for <Datagrid>) outside a ResourceContext without a `resource` prop.","commonSituations":"Previewing rows in Storybook or isolated dev pages; wrapping Datagrid in a component rendered before <Resource> is mounted; forgetting the resource prop when composing rows manually.","solutions":["Pass `resource` explicitly to DatagridRow.","Use DatagridRow inside a <List>/<Datagrid> under a <Resource> route.","Wrap with `<ResourceContextProvider value=\"posts\">` in isolated usage."],"exampleFix":"// before\n<DatagridRow id={id} record={record}>...\n// after\n<DatagridRow id={id} record={record} resource=\"posts\">...","handlingStrategy":"type-guard","validationCode":"const resource = useResourceContext(props);\nif (!resource) {\n  throw new Error('DatagridRow rendered without ResourceContext; pass resource prop');\n}","typeGuard":"const hasResource = <T extends { resource?: string }>(p: T): p is T & { resource: string } =>\n  typeof p.resource === 'string' && p.resource.length > 0;","tryCatchPattern":null,"preventionTips":["Render datagrids under a <Resource> route so ResourceContext exists.","Pass `resource` to rows used in isolation (storybook/tests).","Wrap isolated previews in ResourceContextProvider."],"tags":["react-admin","datagrid","context","resource-context"],"backgroundTag":"missing-provider-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}