Rehooks

useIsMounted

Returns a function to check if the component is currently mounted.

useIsMounted

Installation

npx rehooks-cli@latest add 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

useIsMounted.ts
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