{"record":{"id":"318476705874e4b1","repo":"marmelab/react-admin","slug":"datagridrow-can-only-be-used-within-a-recordcontex","errorCode":null,"errorMessage":"DatagridRow can only be used within a RecordContext or be passed a record prop","messagePattern":"DatagridRow can only be used within a RecordContext or be passed a record prop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx","lineNumber":66,"sourceCode":"        hover = true,\n        id,\n        onToggleItem,\n        record: recordOverride,\n        rowClick,\n        selected = false,\n        style,\n        selectable = true,\n        ...rest\n    } = 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(","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx#L48-L84","documentation":"After checking the id, DatagridRow calls useRecordContext(props) and throws when no record is found: it needs the record data to render cells and compute rowClick. A record must come from an enclosing RecordContext (as inside <Datagrid>) or be passed via the `record` prop.","triggerScenarios":"Rendering <DatagridRow> outside a <Datagrid>/RecordContext without a `record` prop, or in a custom row wrapper that fails to forward the record.","commonSituations":"Reusing DatagridRow in a plain table or list for consistent styling; unit tests mounting DatagridRow bare; a wrapper component that destructures and drops `record`.","solutions":["Render DatagridRow inside a <Datagrid> so RecordContext supplies the record.","Pass `record` explicitly: `<DatagridRow id={record.id} record={record}>...`.","Wrap with `<RecordContextProvider value={record}>` when composing manually."],"exampleFix":"// before\n<DatagridRow id={1} resource=\"posts\">...\n// after\n<DatagridRow id={1} record={post} resource=\"posts\">...","handlingStrategy":"type-guard","validationCode":"const record = useRecordContext(props);\nif (!record) return null; // or render a placeholder instead of DatagridRow","typeGuard":"const hasRecord = <T extends { record?: RaRecord }>(p: T): p is T & { record: RaRecord } =>\n  p.record !== undefined && p.record !== null;","tryCatchPattern":null,"preventionTips":["Use DatagridRow only inside <Datagrid>, or always pass record explicitly.","Don't destructure-and-drop `record` in wrapper components.","In tests, mount rows inside RecordContextProvider."],"tags":["react-admin","datagrid","context","record-context"],"backgroundTag":"missing-provider-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}