diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts index 13c863b1..d3bd8e16 100644 --- a/src/hooks/useLocalStorage.ts +++ b/src/hooks/useLocalStorage.ts @@ -1,4 +1,3 @@ -import { DateTime } from 'luxon'; import { useCallback, useEffect, useMemo, useRef, useState } from 'preact/compat'; import { storageService } from '../services/storage/local'; import { Storage } from '../services/storage/types'; @@ -43,14 +42,14 @@ export interface UseLocalStorageResponse { clear: () => void; } -const hasExpired = (date: DateTime, expire?: number) => { - if (expire === undefined) return false; - return DateTime.now() < date.plus({ seconds: expire }); +const hasExpired = (timestamp: number, expiredMillis?: number) => { + if (expiredMillis === undefined) return false; + return Date.now() < timestamp + expiredMillis; }; const getState = (key: string, defaultValue: T, parse: boolean, expire?: number): T => { const date = expire !== undefined ? storageService.get(`${key}_`) : undefined; - if (date?.length && hasExpired(DateTime.fromMillis(Number(date)), expire)) return defaultValue; + if (date?.length && hasExpired(Date.parse(date), expire)) return defaultValue; if (!parse) return (storageService.get(key) as T) ?? defaultValue; const parsed = storageService.getParsed(key, defaultValue) as T; return defaultValue !== undefined @@ -73,7 +72,7 @@ export const useLocalStorage = ({ const storageSet = useMemo(() => { const internalSet = (key: string, value: unknown) => { storageService.set(key, value); - if (expire !== undefined) storageService.set(`${key}_`, DateTime.now()); + if (expire !== undefined) storageService.set(`${key}_`, Date.now()); }; return debounceTime ? debounce(internalSet, debounceTime) : internalSet; }, [debounceTime, expire]);