{"record":{"id":"0ca254ede1034a00","repo":"marmelab/react-admin","slug":"datatablerow-can-only-be-used-within-a-resourcecon","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":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/test-ui/DataTable.tsx","lineNumber":101,"sourceCode":"    return <>{value?.toString()}</>;\n};\n\nconst DataTableRow = (props: {\n    children: React.ReactNode;\n    record?: RaRecord;\n    resource?: string;\n}) => {\n    const getPathForRecord = useGetPathForRecordCallback();\n    const navigate = useNavigate();\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    if (!resource) {\n        throw new Error(\n            'DataTableRow can only be used within a ResourceContext or be passed a resource prop'\n        );\n    }\n\n    const { hasBulkActions = false } = useDataTableConfigContext();\n    const { handleToggleItem, rowClick } = useDataTableCallbacksContext();\n    const selectedIds = useDataTableSelectedIdsContext();\n\n    const handleClick = useEvent(async (event: React.MouseEvent) => {\n        event.persist();\n        const temporaryLink =\n            typeof rowClick === 'function'\n                ? rowClick(record.id, resource, record)\n                : rowClick;\n\n        const link = isPromise(temporaryLink)\n            ? await temporaryLink\n            : temporaryLink;","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/test-ui/DataTable.tsx#L83-L119","documentation":"DataTableRow also needs to know which resource it belongs to, resolved via useResourceContext from a <ResourceContext> or the `resource` prop. When neither is available, it throws, since row click navigation and permissions depend on the resource name.","triggerScenarios":"Rendering <DataTableRow> outside any ResourceContextProvider and without a resource prop; nesting a DataTable from one resource into another context that doesn't set resource; refactored code removing the resource prop.","commonSituations":"Custom pages rendering DataTable outside <List>/Resource scope; test setups mounting DataTableRow standalone; moving a DataTable into a dashboard widget.","solutions":["Pass resource explicitly: <DataTableRow resource=\"posts\" record={post} />","Wrap in <ResourceContextProvider value=\"posts\">","Render the DataTable inside a List/Resource-scoped component so the resource context exists"],"exampleFix":"// before\n<DataTableRow record={post} />\n\n// after\n<DataTableRow record={post} resource=\"posts\" />\n// or\n<ResourceContextProvider value=\"posts\">\n  <DataTableRow record={post} />\n</ResourceContextProvider>","handlingStrategy":"type-guard","validationCode":"if (!resource) return null; // skip rows without a resource scope\n<DataTableRow resource=\"posts\" record={post} />","typeGuard":"const hasResource = (props: { resource?: string }) =>\n  typeof props.resource === 'string' && props.resource.length > 0;","tryCatchPattern":"try {\n  render(<DataTableRow {...props} />);\n} catch (e) {\n  if (e.message.includes('ResourceContext')) {\n    // supply default resource or skip\n  } else throw e;\n}","preventionTips":["Pass the resource prop when rendering outside List/Resource scope","Wrap ad-hoc tables in ResourceContextProvider","Keep DataTable usage inside List-derived components where possible","Check that refactors didn't strip the resource prop from shared row components"],"tags":["react-admin","resource-context","missing-context","test-ui"],"backgroundTag":"missing-resource-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}