Skip to content

Commit 671d282

Browse files
committed
chore: Not update state when destroyed
1 parent d4c3306 commit 671d282

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/hooks/useStatus.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default function useStatus(
5252

5353
const mountedRef = useRef(false);
5454
const deadlineRef = useRef(null);
55+
const destroyedRef = useRef(false);
5556

5657
// =========================== Dom Node ===========================
5758
const cacheElementRef = useRef<HTMLElement>(null);
@@ -83,7 +84,8 @@ export default function useStatus(
8384
canEnd = onLeaveEnd?.(element, event);
8485
}
8586

86-
if (canEnd !== false) {
87+
// Only update status when `canEnd` and not destroyed
88+
if (canEnd !== false && !destroyedRef.current) {
8789
setStatus(STATUS_NONE);
8890
setStyle(null);
8991
}
@@ -217,6 +219,7 @@ export default function useStatus(
217219
useEffect(
218220
() => () => {
219221
clearTimeout(deadlineRef.current);
222+
destroyedRef.current = true;
220223
},
221224
[],
222225
);

0 commit comments

Comments
 (0)