Skip to content

Commit 4f4b124

Browse files
committed
perf: remove unnecessary setState and init map
1 parent a5b1e9b commit 4f4b124

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/OptionList.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
161161

162162
// ========================= Disabled =========================
163163
// Cache disabled states in React state to ensure re-render when cache updates
164-
const [disabledCache, setDisabledCache] = React.useState<Map<string, boolean>>(new Map());
164+
const [disabledCache, setDisabledCache] = React.useState<Map<string, boolean>>(() => new Map());
165165

166166
React.useEffect(() => {
167167
if (leftMaxCount) {
@@ -184,13 +184,9 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
184184
);
185185

186186
const checkableChildrenCount = checkableChildren.length;
187-
const newCache = new Map(disabledCache);
188-
newCache.set(value, checkableChildrenCount > leftMaxCount);
189-
setDisabledCache(newCache);
187+
disabledCache.set(value, checkableChildrenCount > leftMaxCount);
190188
} else {
191-
const newCache = new Map(disabledCache);
192-
newCache.set(value, false);
193-
setDisabledCache(newCache);
189+
disabledCache.set(value, false);
194190
}
195191
}
196192
return disabledCache.get(value);

0 commit comments

Comments
 (0)