Skip to content

Commit 378e0ed

Browse files
fix(Toolbar): fix onOverflowChange debounce init when the prop is not provided (#4662)
Fixes #4661
1 parent c8d85ad commit 378e0ed

File tree

1 file changed

+7
-3
lines changed
  • packages/main/src/components/Toolbar

1 file changed

+7
-3
lines changed

packages/main/src/components/Toolbar/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ const Toolbar = forwardRef<HTMLDivElement, ToolbarPropTypes>((props, ref) => {
307307
};
308308

309309
const prevChildren = useRef(flatChildren);
310-
const debouncedOverflowChange = useRef(debounce(onOverflowChange, 60));
310+
const debouncedOverflowChange = useRef<ToolbarPropTypes['onOverflowChange'] & { cancel(): void }>();
311311

312312
useEffect(() => {
313-
debouncedOverflowChange.current = debounce(onOverflowChange, 60);
313+
if (typeof onOverflowChange === 'function') {
314+
debouncedOverflowChange.current = debounce(onOverflowChange, 60);
315+
}
314316
}, [onOverflowChange]);
315317

316318
useEffect(() => {
@@ -333,7 +335,9 @@ const Toolbar = forwardRef<HTMLDivElement, ToolbarPropTypes>((props, ref) => {
333335
});
334336
}
335337
return () => {
336-
debouncedOverflowChange.current.cancel();
338+
if (debouncedOverflowChange.current) {
339+
debouncedOverflowChange.current.cancel();
340+
}
337341
};
338342
}, [lastVisibleIndex, flatChildren.length, isPopoverMounted]);
339343

0 commit comments

Comments
 (0)