Skip to content

Commit

Permalink
change provider name and add usememo
Browse files Browse the repository at this point in the history
  • Loading branch information
pvicensSpacedev committed May 21, 2024
1 parent 84b4fcf commit 955d436
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/contexts/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import GlobalLayoutContextProvider from './globalLayout/GlobalLayoutContext';
import SidebarDrawerProvider from './globalLayout/GlobalSidebar/SidebarDrawerContext';
import ModalProvider from './modal/ModalContext';
import NftPreviewFallbackProvider from './nftPreviewFallback/NftPreviewFallbackContext';
import { ProgressProvider } from './onboardingProgress';
import { OnboardingProgressProvider } from './onboardingProgress';
import PostComposerProvider from './postComposer/PostComposerContext';
import SnowProvider from './snow/SnowContext';
import { SwrProvider } from './swr/SwrContext';
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function AppProvider({
globalLayoutContextPreloadedQuery,
}: Props) {
return (
<ProgressProvider>
<OnboardingProgressProvider>
<Boundary>
<ToastProvider>
<MaintenanceStatusProvider
Expand Down Expand Up @@ -106,6 +106,6 @@ export default function AppProvider({
</MaintenanceStatusProvider>
</ToastProvider>
</Boundary>
</ProgressProvider>
</OnboardingProgressProvider>
);
}
16 changes: 8 additions & 8 deletions apps/web/src/contexts/onboardingProgress/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useCallback, useContext, useState } from 'react';
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';

import { ONBOARDING_PROGRESS_BAR_STEPS, StepName } from '~/components/Onboarding/constants';

Expand All @@ -10,7 +10,9 @@ type ProgressContextType = {

const ProgressContext = createContext<ProgressContextType | undefined>(undefined);

export const ProgressProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
export const OnboardingProgressProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [progress, setProgressState] = useState({ from: 0, to: 0 });

const setProgress = useCallback((stepName: StepName) => {
Expand All @@ -20,17 +22,15 @@ export const ProgressProvider: React.FC<{ children: React.ReactNode }> = ({ chil
}
}, []);

return (
<ProgressContext.Provider value={{ ...progress, setProgress }}>
{children}
</ProgressContext.Provider>
);
const contextValue = useMemo(() => ({ ...progress, setProgress }), [progress, setProgress]);

return <ProgressContext.Provider value={contextValue}>{children}</ProgressContext.Provider>;
};

export const useProgress = () => {
const context = useContext(ProgressContext);
if (!context) {
throw new Error('useProgress must be used within a ProgressProvider');
throw new Error('useProgress must be used within a OnboardingProgressProvider');
}
return context;
};

0 comments on commit 955d436

Please sign in to comment.