Skip to content

Commit

Permalink
fix: avoid duplicate requests in fetch column state
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Nov 2, 2024
1 parent 358c1e6 commit ff4bf9b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/widgets/base/one2many/useTreeColumnStorageFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTreeColumnStorage } from "./useTreeColumnStorage";
export const useTreeColumnStorageFetch = (key?: string) => {
const [loading, setLoading] = useState(true);
const columnState = useRef<ColumnState[] | undefined>(undefined);
const fetchInProgress = useRef(false);

const { getColumnState: getColumnStateInternal, updateColumnState } =
useTreeColumnStorage(key);
Expand All @@ -15,13 +16,19 @@ export const useTreeColumnStorageFetch = (key?: string) => {
return;
}
const fetchColumnState = async () => {
if (fetchInProgress.current) {
return;
}

fetchInProgress.current = true;
setLoading(true);
try {
columnState.current = await getColumnStateInternal();
} catch (err) {
console.error(err);
} finally {
setLoading(false);
fetchInProgress.current = false;
}
};

Expand Down

0 comments on commit ff4bf9b

Please sign in to comment.