From 54ff345968a7d81049ecabd06fe691312804e8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Tue, 8 Feb 2022 12:36:52 +0100 Subject: [PATCH] [DDW-881] Memoize part of the useMenuUpdater hook implementation --- .../containers/MenuUpdater/useMenuUpdater.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/renderer/app/containers/MenuUpdater/useMenuUpdater.ts b/source/renderer/app/containers/MenuUpdater/useMenuUpdater.ts index ef6957e23e..ba6c09006d 100644 --- a/source/renderer/app/containers/MenuUpdater/useMenuUpdater.ts +++ b/source/renderer/app/containers/MenuUpdater/useMenuUpdater.ts @@ -1,4 +1,5 @@ -import { useEffect } from 'react'; +import { memoize } from 'lodash/fp'; +import { useEffect, useMemo } from 'react'; import { matchPath } from 'react-router-dom'; import { WalletSettingsStateEnum } from '../../../../common/ipc/api'; import { ROUTES } from '../../routes-config'; @@ -6,20 +7,23 @@ import type { UseMenuUpdaterArgs } from './types'; const walletRoutes = Object.values(ROUTES.WALLETS); +const shouldWalletSettingsOptionBeVisible = memoize((pathname: string) => + walletRoutes.some( + (path) => + matchPath(pathname, { + path, + })?.isExact + ) +); + const useMenuUpdater = ({ stores: { app, profile, router, staking, uiDialogs }, rebuildApplicationMenu, }: UseMenuUpdaterArgs) => { useEffect(() => { let walletSettingsState = WalletSettingsStateEnum.hidden; - const walletSettingsOptionVisible = walletRoutes.some( - (path) => - matchPath(router.location?.pathname, { - path, - })?.isExact - ); - if (walletSettingsOptionVisible) { + if (shouldWalletSettingsOptionBeVisible(router.location?.pathname)) { const itIsTheWalletSettingsPage = matchPath(router.location?.pathname, { path: ROUTES.WALLETS.SETTINGS, })?.isExact;