Skip to content

Commit b17116b

Browse files
authored
Merge pull request #7899 from shreyas-jadhav/reference-array-field-bug-fix
Fix <ReferenceArrayField /> throw error when its value is not an array
2 parents 84052da + 03cd3d4 commit b17116b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/ra-core/src/controller/field/useReferenceArrayFieldController.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import get from 'lodash/get';
2-
2+
import { useMemo } from 'react';
33
import { RaRecord, SortPayload } from '../../types';
44
import { useGetManyAggregate } from '../../dataProvider';
55
import { ListControllerResult, useList } from '../list';
@@ -56,7 +56,14 @@ export const useReferenceArrayFieldController = (
5656
source,
5757
} = props;
5858
const notify = useNotify();
59-
const ids = get(record, source) || emptyArray;
59+
const value = get(record, source);
60+
61+
const ids = useMemo(() => {
62+
if (Array.isArray(value)) return value;
63+
console.warn(`Value of field '${source}' is not an array.`);
64+
return emptyArray;
65+
}, [value, source]);
66+
6067
const { data, error, isLoading, isFetching, refetch } = useGetManyAggregate(
6168
reference,
6269
{ ids },

0 commit comments

Comments
 (0)