UNPKG

reactuals

Version:

A useful package providing a collection of 50+ React hooks and utilities to simplify React development.

15 lines (14 loc) 362 B
import { useEffect, useRef } from "react"; /** * Returns a ref that tells whether the component is mounted. */ export function useIsMounted() { const isMounted = useRef(false); useEffect(() => { isMounted.current = true; return () => { isMounted.current = false; }; }, []); return () => isMounted.current; }