aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-is-mounted.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-04-25 12:57:12 +0200
committerArmand Philippot <git@armandphilippot.com>2022-04-25 12:57:12 +0200
commit8a6f09b564d5d2f02d0a2605f6b52070a910aaa3 (patch)
treecd9e2b6ae6be75f4595b9823e67ebb6bc76df8e8 /src/utils/hooks/use-is-mounted.tsx
parent782a5a1e794a9a8ef6b0b892cd3f386ed583c680 (diff)
chore: add a PageLayout component
Diffstat (limited to 'src/utils/hooks/use-is-mounted.tsx')
-rw-r--r--src/utils/hooks/use-is-mounted.tsx19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/hooks/use-is-mounted.tsx b/src/utils/hooks/use-is-mounted.tsx
new file mode 100644
index 0000000..ca79afb
--- /dev/null
+++ b/src/utils/hooks/use-is-mounted.tsx
@@ -0,0 +1,19 @@
+import { RefObject, useEffect, useState } from 'react';
+
+/**
+ * Check if an HTML element is mounted.
+ *
+ * @param {RefObject<HTMLElement>} ref - A React reference to an HTML element.
+ * @returns {boolean} True if the HTML element is mounted.
+ */
+const useIsMounted = (ref: RefObject<HTMLElement>) => {
+ const [isMounted, setIsMounted] = useState<boolean>(false);
+
+ useEffect(() => {
+ if (ref.current) setIsMounted(true);
+ }, [ref]);
+
+ return isMounted;
+};
+
+export default useIsMounted;