From 26a1e3a7a08e4b0fdb4dfcc3ed6a6cc21bcef104 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 15 Nov 2023 17:15:20 +0100 Subject: refactor(hooks): remove unused hooks * useMutationObserver removed * useStateChange removed --- src/utils/hooks/index.ts | 2 -- src/utils/hooks/use-mutation-observer.tsx | 28 ---------------------------- src/utils/hooks/use-state-change.tsx | 17 ----------------- 3 files changed, 47 deletions(-) delete mode 100644 src/utils/hooks/use-mutation-observer.tsx delete mode 100644 src/utils/hooks/use-state-change.tsx (limited to 'src') diff --git a/src/utils/hooks/index.ts b/src/utils/hooks/index.ts index d42c32b..b3fa627 100644 --- a/src/utils/hooks/index.ts +++ b/src/utils/hooks/index.ts @@ -11,7 +11,6 @@ export * from './use-headings-tree'; export * from './use-is-mounted'; export * from './use-local-storage'; export * from './use-match-media'; -export * from './use-mutation-observer'; export * from './use-on-click-outside'; export * from './use-on-route-change'; export * from './use-pagination'; @@ -24,7 +23,6 @@ export * from './use-reduced-motion'; export * from './use-scroll-lock'; export * from './use-scroll-position'; export * from './use-scrollbar-width'; -export * from './use-state-change'; export * from './use-system-color-scheme'; export * from './use-theme'; export * from './use-timeout'; diff --git a/src/utils/hooks/use-mutation-observer.tsx b/src/utils/hooks/use-mutation-observer.tsx deleted file mode 100644 index c56f7aa..0000000 --- a/src/utils/hooks/use-mutation-observer.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { useEffect } from 'react'; - -type UseMutationObserverProps = { - callback: () => void; - options: MutationObserverInit; - nodeOrSelector: string | HTMLElement; -}; - -export const useMutationObserver = ({ - callback, - options, - nodeOrSelector, -}: UseMutationObserverProps) => { - useEffect(() => { - const targetNode = - typeof nodeOrSelector === 'string' - ? document.querySelector(nodeOrSelector)! - : nodeOrSelector; - - const observer = new MutationObserver(callback); - - observer.observe(targetNode, options); - - return () => { - observer.disconnect(); - }; - }, [nodeOrSelector, options, callback]); -}; diff --git a/src/utils/hooks/use-state-change.tsx b/src/utils/hooks/use-state-change.tsx deleted file mode 100644 index 59ae0df..0000000 --- a/src/utils/hooks/use-state-change.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { useEffect, useState } from 'react'; - -/** - * Use React useState hook and update it if initial data change. - * - * @param initial - The initial value. - * @returns The state and a setter. - */ -export const useStateChange = (initial: T) => { - const [state, setState] = useState(initial); - - useEffect(() => { - setState(initial); - }, [initial]); - - return [state, setState] as const; -}; -- cgit v1.2.3