From 71b6102b394de58df89d6bb34181b3b304a4fcfe Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Thu, 5 Sep 2024 14:56:15 -0500 Subject: [PATCH] Add memoization --- src/components/Setup/SetupProvider.tsx | 20 ++++++++++++++++---- src/components/Setup/useNextSetupPage.ts | 5 +++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Setup/SetupProvider.tsx b/src/components/Setup/SetupProvider.tsx index c2fb1feb14..bf0d1489d6 100644 --- a/src/components/Setup/SetupProvider.tsx +++ b/src/components/Setup/SetupProvider.tsx @@ -1,5 +1,11 @@ import { useRouter } from 'next/router'; -import React, { ReactNode, createContext, useContext, useEffect } from 'react'; +import React, { + ReactNode, + createContext, + useContext, + useEffect, + useMemo, +} from 'react'; import { UserSetupStageEnum } from 'src/graphql/types.generated'; import { useSetupStageQuery } from './Setup.generated'; @@ -49,11 +55,17 @@ export const SetupProvider: React.FC = ({ children }) => { } }, [data]); - const settingUp = data - ? data.userOptions.some( + const settingUp = useMemo(() => { + if (!data) { + return undefined; + } + + return ( + data.userOptions.some( (option) => option.key === 'setup_position' && option.value !== '', ) || data.user.setup !== null - : undefined; + ); + }, [data]); return ( diff --git a/src/components/Setup/useNextSetupPage.ts b/src/components/Setup/useNextSetupPage.ts index fa0bbdfe7d..9829197ab0 100644 --- a/src/components/Setup/useNextSetupPage.ts +++ b/src/components/Setup/useNextSetupPage.ts @@ -1,4 +1,5 @@ import { useRouter } from 'next/router'; +import { useCallback } from 'react'; import { UserSetupStageEnum } from 'src/graphql/types.generated'; import { useUpdateUserOptionsMutation } from '../Contacts/ContactFlow/ContactFlowSetup/UpdateUserOptions.generated'; import { useSetupStageLazyQuery } from './Setup.generated'; @@ -21,7 +22,7 @@ export const useNextSetupPage = (): UseNextSetupPageResult => { }, }); - const next = async () => { + const next = useCallback(async () => { const { data } = await getSetupStage(); switch (data?.user.setup) { case UserSetupStageEnum.NoAccountLists: @@ -40,7 +41,7 @@ export const useNextSetupPage = (): UseNextSetupPageResult => { ); return; } - }; + }, []); return { next,