From df9da03795cd1f34df642e7fd2d2fb23fb3229f9 Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Wed, 1 Jan 2025 18:19:23 +0000 Subject: [PATCH] refactor: memoize DropZone context for minor perf boost --- packages/core/components/DropZone/context.tsx | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/core/components/DropZone/context.tsx b/packages/core/components/DropZone/context.tsx index de408a2c9..c52638c24 100644 --- a/packages/core/components/DropZone/context.tsx +++ b/packages/core/components/DropZone/context.tsx @@ -1,4 +1,10 @@ -import { ReactNode, createContext, useCallback, useState } from "react"; +import { + ReactNode, + createContext, + useCallback, + useMemo, + useState, +} from "react"; import { Config, Data } from "../../types"; import { ItemSelector } from "../../lib/get-item"; @@ -100,21 +106,25 @@ export const DropZoneProvider = ({ [setActiveZones, dispatch] ); + const memoValue = useMemo( + () => + ({ + hoveringComponent, + setHoveringComponent, + registerZoneArea, + areasWithZones, + registerZone, + unregisterZone, + activeZones, + ...value, + } as DropZoneContext), + [value, hoveringComponent, areasWithZones, activeZones] + ); + return ( <> - {value && ( - + {memoValue && ( + {children} )}