Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenie committed Mar 21, 2024
1 parent f73ab99 commit 4f41b44
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions polaris-react/src/utilities/use-index-resource-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export function useIndexResourceState<T extends {[key: string]: unknown}>(
const [dirty, setDirty] = useState(false);

const prevPreCheckedResourcesRef = useRef(preCheckedResources);
const initialSelectedResources = useRef(selectedResources);
const initialUnselectedResources = useRef(unselectedResources);

useEffect(() => {
if (!isEqual(prevPreCheckedResourcesRef.current, preCheckedResources)) {
Expand All @@ -68,6 +70,16 @@ export function useIndexResourceState<T extends {[key: string]: unknown}>(
}
}, [dirty, preCheckedResources, unselectedResources]);

useEffect(() => {
if (
dirty &&
isEqual(initialSelectedResources.current, selectedResources) &&
isEqual(initialUnselectedResources.current, unselectedResources)
) {
setDirty(false);
}
}, [dirty, selectedResources, unselectedResources]);

useEffect(() => {
return () => {
setDirty(false);
Expand Down

0 comments on commit 4f41b44

Please sign in to comment.