{"record":{"id":"02433e385e92198d","repo":"marmelab/react-admin","slug":"datatablerow-can-only-be-used-within-a-recordconte","errorCode":null,"errorMessage":"DataTableRow can only be used within a RecordContext or be passed a record prop","messagePattern":"DataTableRow can only be used within a RecordContext or be passed a record prop","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/test-ui/DataTable.tsx","lineNumber":95,"sourceCode":"        );\n    }\n};\n\nconst DataTableCellValue = (props: { source: string }) => {\n    const value = useFieldValue(props);\n    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'","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/test-ui/DataTable.tsx#L77-L113","documentation":"DataTableRow (react-admin test UI) renders a row for a record and needs to know which record to display and navigate to. It reads the record via useRecordContext; if no record is found in context AND no record prop was supplied, it throws because the row has nothing to render.","triggerScenarios":"Rendering <DataTableRow> outside a <RecordContextProvider> without a `record` prop; using it inside DataTable with records that are undefined/null; forgetting to pass record when composing custom table bodies.","commonSituations":"Custom list layouts built from the test-ui DataTable components; unit tests rendering DataTableRow in isolation; mapping over data where an entry is undefined.","solutions":["Wrap the row in <RecordContextProvider value={record}> or render it inside a component that provides one","Pass the record explicitly: <DataTableRow record={post} />","Guard the render: only render DataTableRow when the record exists"],"exampleFix":"// before\n<DataTableRow resource=\"posts\" />\n\n// after\nposts.map(post => (\n  <RecordContextProvider key={post.id} value={post}>\n    <DataTableRow resource=\"posts\" />\n  </RecordContextProvider>\n))","handlingStrategy":"type-guard","validationCode":"if (!record) return null; // or skip rendering the row\n<DataTableRow resource=\"posts\" record={post} />","typeGuard":"const canRenderRow = (props: { record?: Record }) =>\n  props.record != null;\n// usage: {canRenderRow(props) ? <DataTableRow {...props} /> : null}","tryCatchPattern":"try {\n  render(<DataTableRow {...props} />);\n} catch (e) {\n  if (e.message.includes('DataTableRow can only be used within a RecordContext')) {\n    // render placeholder / skip row\n  } else throw e;\n}","preventionTips":["Always pass record explicitly when DataTableRow is used outside RecordContextProvider","Never map over possibly-undefined array entries; filter first","Wrap rows in RecordContextProvider in custom table layouts","Add a null-record guard before rendering row components"],"tags":["react-admin","record-context","missing-context","test-ui"],"backgroundTag":"missing-record-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}