Skip to content

Commit ebd496d

Browse files
committed
fix not to use event callback to ref callback
1 parent 0b9cb4b commit ebd496d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/scripts/AutoAlign.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {
22
FC,
33
ReactElement,
44
Ref,
5+
useCallback,
56
useContext,
67
useEffect,
78
useMemo,
@@ -346,12 +347,15 @@ function useAutoAlign(props: AutoAlignProps) {
346347
[requestRecalcAlignment]
347348
);
348349

349-
const elRefCallback = useEventCallback((el: HTMLDivElement | null) => {
350-
if (el) {
351-
elRef.current = el;
352-
requestRecalcAlignment();
353-
}
354-
});
350+
const elRefCallback = useCallback(
351+
(el: HTMLDivElement | null) => {
352+
if (el) {
353+
elRef.current = el;
354+
requestRecalcAlignment();
355+
}
356+
},
357+
[requestRecalcAlignment]
358+
);
355359

356360
useEffect(() => {
357361
return () => {

src/scripts/Icon.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, {
66
useRef,
77
useState,
88
useEffect,
9+
useCallback,
910
} from 'react';
1011
import classnames from 'classnames';
1112
import svg4everybody from 'svg4everybody';
@@ -243,13 +244,14 @@ export const Icon = createFC<IconProps, { ICONS: typeof ICONS }>(
243244

244245
const svgIconRef = useRef<SVGSVGElement | null>(null);
245246

246-
const svgIconRefCallback = useEventCallback(
247+
const svgIconRefCallback = useCallback(
247248
(svgEl: SVGSVGElement | null) => {
248249
svgIconRef.current = svgEl;
249250
if (svgEl && props.tabIndex !== undefined) {
250251
svgEl.setAttribute('focusable', (props.tabIndex >= 0).toString());
251252
}
252-
}
253+
},
254+
[props.tabIndex]
253255
);
254256

255257
const [iconColor, setIconColor] = useState<string | null>(null);

0 commit comments

Comments
 (0)