@utilityjs/use-is-mounted
v1.0.2
Published
A React hook that returns `true` if the component is mounted.
Downloads
25
Maintainers
Readme
A React hook that returns true
if the component is mounted.
npm i @utilityjs/use-is-mounted | yarn add @utilityjs/use-is-mounted
Usage
import useGetLatest from "@utilityjs/use-get-latest";
import useIsMounted from "@utilityjs/use-is-mounted";
import * as React from "react";
const useHook = (callback: () => void) => {
const isMounted = useIsMounted();
const getLatestCallback = useGetLatest(callback);
React.useEffect(() => {
const cb = getLatestCallback();
if (isMounted()) cb();
}, []);
};
API
useIsMounted()
declare const useIsMounted: () => (() => boolean);