{"record":{"id":"c7becf510a22db5c","repo":"marmelab/react-admin","slug":"selectrowtablecell-can-only-be-used-within-a-recor","errorCode":null,"errorMessage":"SelectRowTableCell can only be used within a RecordContext","messagePattern":"SelectRowTableCell can only be used within a RecordContext","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/list/datatable/SelectRowCheckbox.tsx","lineNumber":19,"sourceCode":"import React, { useCallback, memo } from 'react';\nimport { Checkbox } from '@mui/material';\nimport {\n    useDataTableSelectedIdsContext,\n    useDataTableCallbacksContext,\n    useTranslate,\n    useRecordContext,\n} from 'ra-core';\n\nimport { DataTableClasses } from './DataTableRoot';\n\nexport const SelectRowCheckbox = memo(() => {\n    const { handleToggleItem, isRowSelectable } =\n        useDataTableCallbacksContext();\n    const selectedIds = useDataTableSelectedIdsContext();\n    const translate = useTranslate();\n    const record = useRecordContext();\n    if (!record) {\n        throw new Error(\n            'SelectRowTableCell can only be used within a RecordContext'\n        );\n    }\n\n    const selectable = !isRowSelectable || isRowSelectable(record);\n    const selected = selectedIds?.includes(record.id);\n\n    const handleToggleSelection = useCallback(\n        event => {\n            if (!selectable || !handleToggleItem) return;\n            handleToggleItem(record.id, event);\n            event.stopPropagation();\n        },\n        [record.id, handleToggleItem, selectable]\n    );\n\n    return (\n        <Checkbox","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/datatable/SelectRowCheckbox.tsx#L1-L37","documentation":"SelectRowCheckbox (rendered in SelectRowTableCell) reads the current record via useRecordContext to determine selection state and selectability. With no record in context it cannot compute `record.id`, so react-admin throws immediately.","triggerScenarios":"Rendering <SelectRowTableCell> in a table row outside a RecordContext, e.g. a header row or a custom cell not wrapped by <RecordContextProvider>.","commonSituations":"Custom DataTable configurations where the select cell is placed outside <DataTableRow>, or manual <Table> assembly without a record scope.","solutions":["Render the cell within <DataTableRow> or wrap it in <RecordContextProvider value={record}>.","Use <DataTable> inside a <List> so both record and callback contexts are populated.","Remove the select cell from rows that intentionally have no record."],"exampleFix":"// before\n<TableCell><SelectRowTableCell /></TableCell>\n// after\n<RecordContextProvider value={record}>\n  <TableCell><SelectRowTableCell /></TableCell>\n</RecordContextProvider>","handlingStrategy":"validation","validationCode":"const record = useRecordContext();\nif (!record) return null; // or throw before rendering SelectRowTableCell","typeGuard":"const hasRecord = (r: RaRecord | null | undefined): r is RaRecord => !!r && typeof r.id !== 'undefined';","tryCatchPattern":"try { renderCell(); } catch (e) { if (String(e).includes('SelectRowTableCell')) return null; throw e; }","preventionTips":["Only place SelectRowTableCell inside DataTableRow rows.","Wrap custom rows with RecordContextProvider.","Return early (null) when useRecordContext() is undefined."],"tags":["react-admin","missing-context","record-context"],"backgroundTag":"missing-context-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}