fix(governance): removed loop caused by rewards epoch refresh (#4864)

This commit is contained in:
Sam Keen 2023-09-25 10:34:47 +01:00 committed by GitHub
parent 525773773a
commit 9cbd6baccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import { useMemo, useEffect, useState, useCallback } from 'react'; import { useMemo, useEffect, useState, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit'; import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit';
import { removePaginationWrapper } from '@vegaprotocol/utils'; import { removePaginationWrapper } from '@vegaprotocol/utils';
@ -86,12 +86,18 @@ export const EpochIndividualRewards = ({
[epochId, page, refetch, delegationsPagination, pubKey] [epochId, page, refetch, delegationsPagination, pubKey]
); );
const prevEpochIdRef = useRef<number | null>(null);
useEffect(() => { useEffect(() => {
// when the epoch changes, we want to refetch the data to update the current page if (prevEpochIdRef.current === null) {
if (data) { prevEpochIdRef.current = epochId;
} else if (epochId !== prevEpochIdRef.current) {
// When the epoch changes, we want to refetch the data to update the current page
refetchData(); refetchData();
} }
}, [epochId, data, refetchData]);
prevEpochIdRef.current = epochId;
}, [epochId, refetchData]);
return ( return (
<AsyncRenderer <AsyncRenderer