Skip to content

[Docs] Fix custom field uses defaultProps for labels - #11367

Merged
fzaninotto merged 2 commits into
marmelab:masterfrom
jabrailkhalil:docs/custom-field-explicit-label
Sep 10, 2026
Merged

fzaninotto merged 2 commits into
marmelab:masterfrom
jabrailkhalil:docs/custom-field-explicit-label

Conversation

@jabrailkhalil

@jabrailkhalil jabrailkhalil commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

The custom field example recommends function-component defaultProps, which React 19 no longer supports. Replacing it with a default function parameter would not expose the label to the parent layout.

Closes #10684.

Solution

Pass label="Name" explicitly when using FullNameField and explain why the label belongs on the element. The existing Datagrid example and sorting source remain intact.

How To Test

Reviewed the example against DatagridHeaderCell and Labeled, which read the label from the child element's props. git diff --check passes. Documentation build and browser rendering were not run.

Additional Checks

  • Targets master for a documentation fix
  • Unit tests and stories: not applicable; this changes only an existing documentation example
  • Documentation updated

Comment thread docs/Fields.md Outdated
**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`.

You can now use this field like any other react-admin field:
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. A default parameter inside `FullNameField` would not be visible to the parent layout, and React 19 no longer supports `defaultProps` for function components:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the last sentence: "A default parameter..."

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

Thanks @fzaninotto! Removed the last sentence as suggested.

@fzaninotto
fzaninotto merged commit 4e469da into marmelab:master Sep 10, 2026
2 checks passed
@fzaninotto

Copy link
Copy Markdown
Member

Thanks!

@fzaninotto fzaninotto added this to the 5.15.4 milestone Sep 10, 2026
@fzaninotto fzaninotto changed the title docs: pass custom field labels explicitly [Docs] Fix custom field uses defaultProps for labels Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defaultProps recommended for label of custom field

2 participants