Rehooks
Content

useIsMounted

A custom React hook that returns a function to check if the component is currently mounted.

useIsMounted

Usage

Component.tsx
import { useIsMounted } from "~/hooks/useIsMounted";
 
function Component() {
  const isMounted = useIsMounted();
 
  useEffect(() => {
    if (isMounted()) {
      // Do something when the component is mounted
    }
  }, [isMounted]);
 
  return <div>Component</div>;
}

API

useIsMounted

function useIsMounted(): () => boolean;

Returns a function that returns a boolean indicating whether the component is currently mounted.

Returns

NameTypeDescription
isMounted() => booleanA function that returns a boolean indicating whether the component is currently mounted.

On this page