mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
430883f186
Towards #9278
20 lines
436 B
TypeScript
20 lines
436 B
TypeScript
import * as React from "react";
|
|
|
|
/**
|
|
* Hook to check if component is still mounted
|
|
*
|
|
* @returns true if the component is mounted, false otherwise
|
|
*/
|
|
export default function useIsMounted(): () => boolean {
|
|
const isMounted = React.useRef(false);
|
|
|
|
React.useEffect(() => {
|
|
isMounted.current = true;
|
|
return () => {
|
|
isMounted.current = false;
|
|
};
|
|
}, []);
|
|
|
|
return React.useCallback(() => isMounted.current, []);
|
|
}
|