Skip to content

Commit

Permalink
Merge pull request #8851 from marmelab/doc-withrecord-datagrid
Browse files Browse the repository at this point in the history
[Doc] Fix WithRecord usage in Datagrid to remind the label requirement
  • Loading branch information
slax57 committed Apr 24, 2023
2 parents c98aa74 + 73cd2d0 commit 0572a66
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/WithRecord.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ As soon as there is a record available, react-admin puts it in a `RecordContext`
- in descendants of the `<SimpleList>` component
- in descendants of the `<ReferenceField>` component

## Using in a Datagrid

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.

```jsx
import { Datagrid, TextField, WithRecord } from 'react-admin';

const PostList = () => (
<List>
<Datagrid>
<TextField source="title" />
<WithRecord label="author" render={record => <span>{record.author}</span>} />
</Datagrid>
</List>
);
```

## See Also

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

0 comments on commit 0572a66

Please sign in to comment.