aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-local-storage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/hooks/use-local-storage.tsx')
-rw-r--r--src/utils/hooks/use-local-storage.tsx33
1 files changed, 0 insertions, 33 deletions
diff --git a/src/utils/hooks/use-local-storage.tsx b/src/utils/hooks/use-local-storage.tsx
deleted file mode 100644
index 0f9fbb6..0000000
--- a/src/utils/hooks/use-local-storage.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { LocalStorage } from '../../services/local-storage';
-import { Dispatch, SetStateAction, useEffect, useState } from 'react';
-
-export type UseLocalStorageReturn<T> = {
- value: T;
- setValue: Dispatch<SetStateAction<T>>;
-};
-
-/**
- * Use the local storage.
- *
- * @param {string} key - The storage local key.
- * @param {T} [fallbackValue] - A fallback value if local storage is empty.
- * @returns {UseLocalStorageReturn<T>} An object with value and setValue.
- */
-export const useLocalStorage = <T,>(
- key: string,
- fallbackValue: T
-): UseLocalStorageReturn<T> => {
- const getInitialValue = () => {
- if (typeof window === 'undefined') return fallbackValue;
- const storedValue = LocalStorage.get<T>(key);
- return storedValue ?? fallbackValue;
- };
-
- const [value, setValue] = useState<T>(getInitialValue);
-
- useEffect(() => {
- LocalStorage.set(key, value);
- }, [key, value]);
-
- return { value, setValue };
-};