accounts-frontend/packages/app/hooks/useIsMounted.ts
ErickSkrauch af59cc033f
Extract device code into a separate view.
Convert more components from class components to functional.
Fix invalid finish state when client was auto approved
2024-12-14 13:16:29 +01:00

18 lines
547 B
TypeScript

import { useCallback, useEffect, useRef } from 'react';
// This code is copied from the usehooks-ts: https://usehooks-ts.com/react-hook/use-is-mounted
// Replace it with the library when the Node.js version of the project will be updated at least to 16.
export default function useIsMounted(): () => boolean {
const isMounted = useRef(false);
useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
return useCallback(() => isMounted.current, []);
}