diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-15 17:15:20 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-15 17:26:17 +0100 |
| commit | 26a1e3a7a08e4b0fdb4dfcc3ed6a6cc21bcef104 (patch) | |
| tree | 68d0ddf7cdc1e83f3f56607f6c4fee1f0bbd9820 /src/utils | |
| parent | 36baf3e5725aeae00d81d3a082b3c04074e09f8e (diff) | |
refactor(hooks): remove unused hooks
* useMutationObserver removed
* useStateChange removed
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/hooks/index.ts | 2 | ||||
| -rw-r--r-- | src/utils/hooks/use-mutation-observer.tsx | 28 | ||||
| -rw-r--r-- | src/utils/hooks/use-state-change.tsx | 17 |
3 files changed, 0 insertions, 47 deletions
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 = <T,>(initial: T) => { - const [state, setState] = useState<T>(initial); - - useEffect(() => { - setState(initial); - }, [initial]); - - return [state, setState] as const; -}; |
