Skip to content

defaultProps recommended for label of custom field #10684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hco opened this issue Apr 18, 2025 · 4 comments
Open

defaultProps recommended for label of custom field #10684

hco opened this issue Apr 18, 2025 · 4 comments

Comments

@hco
Copy link

hco commented Apr 18, 2025

On https://marmelab.com/react-admin/Fields.html#writing-your-own-field-component, it is recommended to use defaultProps for having a default label for a custom field.

As defaultProps for function components do not exist anymore, another way should be recommended.

Other information:
Mention on defaultProps being removed: https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-react-apis

@fzaninotto
Copy link
Member

Thanks for pointing this. I'm marking it as a documentation issue.

We won't need defaultProps for labellingcustom fields in a data grid with the new DataTable component. We will need to use the same approach for the Show layouts, and then we can stop recommending setting the label on Field components altogether.

@dhfra21
Copy link

dhfra21 commented Apr 25, 2025

I've updated the documentation to remove the defaultProps pattern for custom field components. The changes include:

  1. Updated the FullNameField example in Fields.md to use parameter destructuring with source and ...props instead of label and ...props
  2. Updated the ColoredNumberField example in SX.md to:
    Remove the defaultProps assignment
    Use parameter destructuring with source and ...props
    Pass the source prop explicitly to the underlying component
    Should I proceed with a PR ?

@fzaninotto
Copy link
Member

As explained in #10699, what you propose doesn't work.

@dhfra21
Copy link

dhfra21 commented Apr 25, 2025

got it! i'll look for another solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants