{"record":{"id":"d9fbc79a43fcb720","repo":"marmelab/react-admin","slug":"datatablerow-can-only-be-used-within-a-resourcecon-d9fbc7","errorCode":null,"errorMessage":"DataTableRow can only be used within a ResourceContext or be passed a resource prop","messagePattern":"DataTableRow 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/datatable/DataTableRow.tsx","lineNumber":71,"sourceCode":"            hasBulkActions = false,\n            hover = true,\n        } = useDataTableConfigContext();\n\n        const { handleToggleItem, isRowExpandable, isRowSelectable, rowClick } =\n            useDataTableCallbacksContext();\n\n        const record = useRecordContext(props);\n        if (!record) {\n            throw new Error(\n                'DataTableRow 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                'DataTableRow can only be used within a ResourceContext or be passed a resource prop'\n            );\n        }\n        const selectable = !isRowSelectable || isRowSelectable(record);\n        const expandable =\n            (!isRowExpandable || isRowExpandable(record)) && expand;\n        const [expanded, toggleExpanded] = useExpanded(\n            resource,\n            record.id,\n            expandSingle\n        );\n        const [nbColumns, setNbColumns] = useState(() =>\n            computeNbColumns(expandable, children, hasBulkActions)\n        );\n        useEffect(() => {\n            // Fields can be hidden dynamically based on permissions;\n            // The expand panel must span over the remaining columns\n            // So we must recompute the number of columns to span on","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/datatable/DataTableRow.tsx#L53-L89","documentation":"DataTableRow resolves its resource via useResourceContext (either the ResourceContext from a surrounding <Resource>/<ListContext> or an explicit resource prop). react-admin throws when neither exists, because without a resource name it cannot resolve the record's list route, row click behavior, or resource definition (hasShow/hasEdit).","triggerScenarios":"Rendering <DataTableRow> outside a ListContext/ResourceContext (e.g. in a plain <TableBody> or custom page) without passing resource=\"posts\".","commonSituations":"Custom standalone tables, storybook examples, or extracting a row component out of a <DataTable> without threading the resource down.","solutions":["Pass an explicit resource prop: <DataTableRow resource=\"posts\" ...>.","Render the row inside a ListContext/ResourceContextProvider supplying the resource.","Use <DataTable> inside a <List> so the resource context is provided automatically."],"exampleFix":"// before\n<TableBody><DataTableRow record={record} /></TableBody>\n// after\n<TableBody><DataTableRow resource=\"posts\" record={record} /></TableBody>","handlingStrategy":"validation","validationCode":"if (!resource) throw new Error('DataTableRow requires a resource: wrap in <List>/<Resource> or pass resource prop');","typeGuard":"const hasResource = (p: { resource?: string }): p is { resource: string } => typeof p.resource === 'string' && p.resource.length > 0;","tryCatchPattern":"try { renderRow(); } catch (e) { if (String(e).includes('DataTableRow can only be used')) return <DataTableRow resource=\"posts\" {...rowProps} />; throw e; }","preventionTips":["Always render DataTableRow inside <DataTable>/<List>.","Thread the resource prop in extracted row components.","Add a lint rule requiring resource on standalone list primitives."],"tags":["react-admin","missing-context","resource-prop"],"backgroundTag":"missing-context-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}