Skip to content

Commit

Permalink
use memo for slide context
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkaterina committed Feb 26, 2024
1 parent c191251 commit 5fc33c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
25 changes: 10 additions & 15 deletions src/app/context/context-providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ import { StatusProvider } from './status-context'
export default function ContextProviders({ children }: any) {

return (
<CurrentRecipeProvider>
<CurrentMenuProvider>
<CardOpenProvider>
<CurrentFoodProvider>
<SlideProvider>
<AuthProvider>
<StatusProvider>
{children}
</StatusProvider>
</AuthProvider>
</SlideProvider>
</CurrentFoodProvider>
</CardOpenProvider>
</CurrentMenuProvider>
</CurrentRecipeProvider>
<>
<CurrentRecipeProvider/>
<CurrentMenuProvider/>
<CardOpenProvider/>
<CurrentFoodProvider/>
<SlideProvider/>
<AuthProvider/>
<StatusProvider/>
{children}
</>
);
}
20 changes: 11 additions & 9 deletions src/app/context/slide-context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useState } from "react";
import { createContext, useState, useMemo } from "react";
import { SlideType } from '@/app/types/types';

type ScrollBehavior = 'auto' | 'smooth';
Expand Down Expand Up @@ -27,15 +27,17 @@ export const SlideProvider = ({ children }: any) => {
const [blockScroll, setBlockScroll] = useState<boolean>(false);
const [scrollBehavior, setScrollBehavior] = useState<ScrollBehavior>('smooth');

const contextValue = useMemo(() => ({
slide,
setSlide,
blockScroll,
setBlockScroll,
scrollBehavior,
setScrollBehavior
}), [slide, setSlide, blockScroll, setBlockScroll, scrollBehavior, setScrollBehavior]);

return (
<SlideContext.Provider value={{
slide,
setSlide,
blockScroll,
setBlockScroll,
scrollBehavior,
setScrollBehavior
}}>
<SlideContext.Provider value={contextValue}>
{children}
</SlideContext.Provider>
);
Expand Down

0 comments on commit 5fc33c5

Please sign in to comment.