@technote-space/use-unmount-ref
v0.1.32
Published
React hook to handle unmount ref.
Downloads
16
Readme
useUnmountRef
React hook to handle unmount ref.
Table of Contents
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>
};