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 state update issue in ReferenceArrayInput #7165

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
import { useMemo, useEffect, useRef, useCallback } from 'react';
import { useSelector } from 'react-redux';
import isEqual from 'lodash/isEqual';
import difference from 'lodash/difference';
Expand Down Expand Up @@ -59,8 +59,10 @@ export const useReferenceArrayInputController = (
// We store the current input value in a ref so that we are able to fetch
// only the missing references when the input value changes
const inputValue = useRef(input.value);
const [idsToFetch, setIdsToFetch] = useState(input.value);
const [idsToGetFromStore, setIdsToGetFromStore] = useState(EmptyArray);
const [idsToFetch, setIdsToFetch] = useSafeSetState(input.value);
const [idsToGetFromStore, setIdsToGetFromStore] = useSafeSetState(
EmptyArray
);
const referenceRecordsFromStore = useSelector((state: ReduxState) =>
idsToGetFromStore.map(id => state.admin.resources[reference].data[id])
);
Expand Down Expand Up @@ -186,7 +188,7 @@ export const useReferenceArrayInputController = (
}, [setPagination, initialPage, initialPerPage]);

// filter logic
const [queryFilter, setFilter] = useState('');
const [queryFilter, setFilter] = useSafeSetState('');
const filterRef = useRef(defaultFilter);
const [displayedFilters, setDisplayedFilters] = useSafeSetState<{
[key: string]: boolean;
Expand Down