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 { current: scheduledTimers } = useRef(new Set<number>());
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
useEffect(() => {
|
||||
didUnmountRef.current = false;
|
||||
|
||||
return () => {
|
||||
didUnmountRef.current = true;
|
||||
clearAll();
|
||||
},
|
||||
[],
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
function clearAll() {
|
||||
scheduledTimers.forEach((timer) => clearTimeout(timer));
|
||||
|
|
Loading…
Reference in a new issue