UNPKG

react-use-mounted

Version:

React hook for checking if the component is mounted.

16 lines (15 loc) 329 B
/* IMPORT */ import { useEffect, useRef } from 'react'; /* MAIN */ const useMounted = () => { const mounted = useRef(false); useEffect(() => { mounted.current = true; return () => { mounted.current = false; }; }, []); return mounted; }; /* EXPORT */ export default useMounted;