From 5fc33c512a588a965cbdf16e49f4bb42de0a7911 Mon Sep 17 00:00:00 2001 From: jwkaterina Date: Mon, 26 Feb 2024 10:03:06 +0100 Subject: [PATCH] use memo for slide context --- src/app/context/context-providers.tsx | 25 ++++++++++--------------- src/app/context/slide-context.tsx | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/app/context/context-providers.tsx b/src/app/context/context-providers.tsx index 025a534..9cae156 100644 --- a/src/app/context/context-providers.tsx +++ b/src/app/context/context-providers.tsx @@ -9,20 +9,15 @@ import { StatusProvider } from './status-context' export default function ContextProviders({ children }: any) { return ( - - - - - - - - {children} - - - - - - - + <> + + + + + + + + {children} + ); } \ No newline at end of file diff --git a/src/app/context/slide-context.tsx b/src/app/context/slide-context.tsx index 6b26c72..3cb0a46 100644 --- a/src/app/context/slide-context.tsx +++ b/src/app/context/slide-context.tsx @@ -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'; @@ -27,15 +27,17 @@ export const SlideProvider = ({ children }: any) => { const [blockScroll, setBlockScroll] = useState(false); const [scrollBehavior, setScrollBehavior] = useState('smooth'); + const contextValue = useMemo(() => ({ + slide, + setSlide, + blockScroll, + setBlockScroll, + scrollBehavior, + setScrollBehavior + }), [slide, setSlide, blockScroll, setBlockScroll, scrollBehavior, setScrollBehavior]); + return ( - + {children} );