Skip to content

Commit

Permalink
chore: memoize wallet lists to prevent rerenders
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-deriv committed Oct 23, 2024
1 parent d00d49b commit deb84cf
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import useEmblaCarousel, { EmblaCarouselType, EmblaEventType } from 'embla-carousel-react';
import { useHistory } from 'react-router-dom';
import { useActiveWalletAccount, useCurrencyConfig, useMobileCarouselWalletsList } from '@deriv/api-v2';
Expand Down Expand Up @@ -45,8 +45,14 @@ const WalletsCarouselContent: React.FC<TProps> = ({ accountsActiveTabIndex }) =>
const [currentIndex, setCurrentIndex] = useState(-1);
const [isInitialDataLoaded, setIsInitialDataLoaded] = useState(false);

const walletAccountsList = walletAccountsListData?.filter(wallet => !wallet.is_disabled);
const disabledWallets = walletAccountsListData?.filter(wallet => wallet.is_disabled) ?? [];
const walletAccountsList = useMemo(
() => walletAccountsListData?.filter(wallet => !wallet.is_disabled),
[walletAccountsListData]
);
const disabledWallets = useMemo(
() => walletAccountsListData?.filter(wallet => wallet.is_disabled) ?? [],
[walletAccountsListData]
);

// for the embla "on select" callback
// to avoid unbinding / cleaning etc, just let it use up-to-date list
Expand Down

0 comments on commit deb84cf

Please sign in to comment.