Categories
Hook10Checks if a component is mounted.
Contributed by @itsbrunodev
import { useEffect, useRef } from "react";
 
function useIsMounted(): () => boolean {
  const isMounted = useRef(true);
 
  useEffect(() => {
    return () => {
      isMounted.current = false;
    };
  }, []);
 
  return () => isMounted.current;
}const isMounted = useIsMounted(); // true