Bin
2025-12-17 05a69820e0c402b0b33c063d3b922f0a0571cbbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useEffect, useRef } from "react";
 
/**
 * Protects async tasks from causing memory leaks in other effects/callbacks.
 * Wrap any set states within a component with
 *
 * if (mounted.current) {  ...  }
 */
export const useMounted = () => {
  const mounted = useRef(true);
 
  useEffect(() => {
    mounted.current = true;
    return () => {
      mounted.current = false;
    };
  }, []);
 
  return mounted;
};