Skip to content

Commit df9da03

Browse files
committed
refactor: memoize DropZone context for minor perf boost
1 parent 6be76bc commit df9da03

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

packages/core/components/DropZone/context.tsx

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ReactNode, createContext, useCallback, useState } from "react";
1+
import {
2+
ReactNode,
3+
createContext,
4+
useCallback,
5+
useMemo,
6+
useState,
7+
} from "react";
28
import { Config, Data } from "../../types";
39
import { ItemSelector } from "../../lib/get-item";
410

@@ -100,21 +106,25 @@ export const DropZoneProvider = ({
100106
[setActiveZones, dispatch]
101107
);
102108

109+
const memoValue = useMemo(
110+
() =>
111+
({
112+
hoveringComponent,
113+
setHoveringComponent,
114+
registerZoneArea,
115+
areasWithZones,
116+
registerZone,
117+
unregisterZone,
118+
activeZones,
119+
...value,
120+
} as DropZoneContext),
121+
[value, hoveringComponent, areasWithZones, activeZones]
122+
);
123+
103124
return (
104125
<>
105-
{value && (
106-
<dropZoneContext.Provider
107-
value={{
108-
hoveringComponent,
109-
setHoveringComponent,
110-
registerZoneArea,
111-
areasWithZones,
112-
registerZone,
113-
unregisterZone,
114-
activeZones,
115-
...value,
116-
}}
117-
>
126+
{memoValue && (
127+
<dropZoneContext.Provider value={memoValue}>
118128
{children}
119129
</dropZoneContext.Provider>
120130
)}

0 commit comments

Comments
 (0)