Skip to content

technote-space/use-unmount-ref

Repository files navigation

useUnmountRef

npm version CI Status codecov CodeFactor License: MIT

React hook to handle unmount ref.

Table of Contents

Details

Usage

Install

yarn add @technote-space/use-unmount-ref

or

npm i @technote-space/use-unmount-ref

Use

e.g.

import type { FC } from 'react';
import { useEffect, useState } from 'react';
import useUnmountRef from '@technote-space/use-unmount-ref';

const TestPage: FC = () => {
  const unmountRef = useUnmountRef();
  const [isLoading, setIsLoading] = useState(false);
  
  useEffect(() => {
    setIsLoading(true);
    setTimeout(() => {
      if(!unmountRef.current) {
        setIsLoading(false);
      }
    }, 1000);
  }, []);
  
  return <div>
    {isLoading ? 'Loading...' : 'Not loading.'}
  </div>
};

Author

GitHub (Technote)
Blog