From aec35daddf0304ea6db1f72d1adb1d7e332b6f33 Mon Sep 17 00:00:00 2001 From: dhfra21 Date: Fri, 25 Apr 2025 12:30:39 +0100 Subject: [PATCH] docs: update field component example to use modern React patterns --- docs/Fields.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/Fields.md b/docs/Fields.md index 8446467b15b..b6d9f867fdd 100644 --- a/docs/Fields.md +++ b/docs/Fields.md @@ -482,12 +482,10 @@ Here is a custom field displaying the full name: ```jsx import { useRecordContext } from 'react-admin'; -export const FullNameField = (props) => { +export const FullNameField = ({ label = 'Name', ...props }) => { const record = useRecordContext(props); return record ? {record.firstName} {record.lastName} : null; } - -FullNameField.defaultProps = { label: 'Name' }; ``` **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`.