Skip to content
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

Fix <ReferenceArrayField /> throw error when its value is not an array #7899

Merged
merged 7 commits into from
Jul 6, 2022
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get from 'lodash/get';

import { useMemo } from 'react';
import { RaRecord, SortPayload } from '../../types';
import { useGetManyAggregate } from '../../dataProvider';
import { ListControllerResult, useList } from '../list';
Expand Down Expand Up @@ -56,7 +56,14 @@ export const useReferenceArrayFieldController = (
source,
} = props;
const notify = useNotify();
const ids = get(record, source) || emptyArray;
const value = get(record, source);

const ids = useMemo(() => {
if (Array.isArray(value)) return value;
console.warn(`Value of field '${source}' is not an array.`);
return emptyArray;
}, [value, source]);

const { data, error, isLoading, isFetching, refetch } = useGetManyAggregate(
reference,
{ ids },
Expand Down