Skip to content

Commit 0572a66

Browse files
authored
Merge pull request #8851 from marmelab/doc-withrecord-datagrid
[Doc] Fix WithRecord usage in Datagrid to remind the label requirement
2 parents c98aa74 + 73cd2d0 commit 0572a66

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

docs/WithRecord.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ As soon as there is a record available, react-admin puts it in a `RecordContext`
3636
- in descendants of the `<SimpleList>` component
3737
- in descendants of the `<ReferenceField>` component
3838

39+
## Using in a Datagrid
40+
41+
When using `<WithRecord>` in a [`<Datagrid>`](./Datagrid.md), you must specify the `label` prop to let react-admin know which field to display in the column header.
42+
43+
```jsx
44+
import { Datagrid, TextField, WithRecord } from 'react-admin';
45+
46+
const PostList = () => (
47+
<List>
48+
<Datagrid>
49+
<TextField source="title" />
50+
<WithRecord label="author" render={record => <span>{record.author}</span>} />
51+
</Datagrid>
52+
</List>
53+
);
54+
```
55+
3956
## See Also
4057

4158
* [`useRecordContext`](./useRecordContext.md) is the hook version of this component.

0 commit comments

Comments
 (0)