From 4ba697b4f931cc6aa9acb9ec22310e0763eb604a Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Thu, 12 Dec 2019 08:07:51 +0100 Subject: [PATCH 1/2] Fix ReferenceField when used inside form Closes #4124 --- packages/ra-ui-materialui/src/field/ReferenceField.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/field/ReferenceField.js b/packages/ra-ui-materialui/src/field/ReferenceField.js index 8e718788958..c23686d40cc 100644 --- a/packages/ra-ui-materialui/src/field/ReferenceField.js +++ b/packages/ra-ui-materialui/src/field/ReferenceField.js @@ -110,7 +110,6 @@ ReferenceField.defaultProps = { addLabel: true, classes: {}, link: 'edit', - record: {}, }; const useStyles = makeStyles(theme => ({ From a7a2b835703660b8d43b27e9c9bcff4c841562f9 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Thu, 12 Dec 2019 08:53:09 +0100 Subject: [PATCH 2/2] no need to pass all props --- packages/ra-ui-materialui/src/field/ReferenceField.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ra-ui-materialui/src/field/ReferenceField.js b/packages/ra-ui-materialui/src/field/ReferenceField.js index c23686d40cc..2690647fdd6 100644 --- a/packages/ra-ui-materialui/src/field/ReferenceField.js +++ b/packages/ra-ui-materialui/src/field/ReferenceField.js @@ -59,10 +59,9 @@ const ReferenceField = ({ children, record, source, ...props }) => { if (React.Children.count(children) !== 1) { throw new Error(' only accepts a single child'); } - const id = get(record, source); const { loaded, error, referenceRecord } = useReference({ - ...props, - id, + reference: props.reference, + id: get(record, source), }); const resourceLinkPath = getResourceLinkPath({ record, source, ...props });