Skip to content

Commit 4e469da

Browse files
authored
Merge pull request #11367 from jabrailkhalil/docs/custom-field-explicit-label
docs: pass custom field labels explicitly
2 parents 808e6d7 + 5b4099b commit 4e469da

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎docs/Fields.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,11 @@ export const FullNameField = (props) => {
495495
const record = useRecordContext(props);
496496
return record ? <span>{record.firstName} {record.lastName}</span> : null;
497497
}
498-
499-
FullNameField.defaultProps = { label: 'Name' };
500498
```
501499

502500
**Tip**: Always check the `record` is defined before inspecting its properties, as react-admin may display the Show view *before* fetching the record from the data provider. So the first time it renders the show view for a resource, the `record` is `undefined`.
503501

504-
You can now use this field like any other react-admin field:
502+
You can now use this field like any other react-admin field. Pass the `label` explicitly so the parent layout can read it from the field's props:
505503

506504
```jsx
507505
import { List, Datagrid } from 'react-admin';
@@ -510,7 +508,7 @@ import { FullNameField } from './FullNameField';
510508
export const UserList = () => (
511509
<List>
512510
<Datagrid>
513-
<FullNameField source="lastName" />
511+
<FullNameField source="lastName" label="Name" />
514512
</Datagrid>
515513
</List>
516514
);

0 commit comments

Comments
 (0)