Ensure mounted state in useSetTimeout()
remains consistent (#22025)
This commit is contained in:
parent
08dfdffbfb
commit
fa592f882a
1 changed files with 6 additions and 5 deletions
|
@ -4,13 +4,14 @@ export default function useSetTimeout() {
|
||||||
const didUnmountRef = useRef(false);
|
const didUnmountRef = useRef(false);
|
||||||
const { current: scheduledTimers } = useRef(new Set<number>());
|
const { current: scheduledTimers } = useRef(new Set<number>());
|
||||||
|
|
||||||
useEffect(
|
useEffect(() => {
|
||||||
() => () => {
|
didUnmountRef.current = false;
|
||||||
|
|
||||||
|
return () => {
|
||||||
didUnmountRef.current = true;
|
didUnmountRef.current = true;
|
||||||
clearAll();
|
clearAll();
|
||||||
},
|
};
|
||||||
[],
|
}, []);
|
||||||
);
|
|
||||||
|
|
||||||
function clearAll() {
|
function clearAll() {
|
||||||
scheduledTimers.forEach((timer) => clearTimeout(timer));
|
scheduledTimers.forEach((timer) => clearTimeout(timer));
|
||||||
|
|
Loading…
Reference in a new issue