diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e2168..d4dd1d1 100644 Binary files a/CHANGELOG.md and b/CHANGELOG.md differ diff --git a/lib/ReactiveStorage.ts b/lib/ReactiveStorage.ts index 48d086e..a8ab8a8 100644 --- a/lib/ReactiveStorage.ts +++ b/lib/ReactiveStorage.ts @@ -77,5 +77,5 @@ class Crypto { } } -const encryption = await Crypto.createInstance(); +const encryption = Crypto.createInstance(); export { encryption }; \ No newline at end of file diff --git a/lib/hooks/useLsState.ts b/lib/hooks/useLsState.ts index c77d495..474bb3b 100644 --- a/lib/hooks/useLsState.ts +++ b/lib/hooks/useLsState.ts @@ -6,14 +6,14 @@ const get = async (key: string): Promise => { if (value === null) { return value; } if (ReactiveStorage.isEncrypted()) { - return JSON.parse(await encryption.decrypt(value)) as T; + return JSON.parse(await (await encryption).decrypt(value)) as T; } else return JSON.parse(value) as T; } const set = async (key: string, value: T | null): Promise => { if (ReactiveStorage.isEncrypted()) { - localStorage.setItem(key, await encryption.encrypt(JSON.stringify(value))) + localStorage.setItem(key, await (await encryption).encrypt(JSON.stringify(value))) } else localStorage.setItem(key, JSON.stringify(value)); } @@ -28,7 +28,7 @@ const useLsState = (key: string, defaultValue?: T): [T | null, (value: T) => } const onStorageChange = async (e: StorageEvent) => { - if(e.key == key) { _setState(await get(key)); } + if (e.key == key) { _setState(await get(key)); } } useEffect(() => { @@ -38,10 +38,10 @@ const useLsState = (key: string, defaultValue?: T): [T | null, (value: T) => }; getInitialValue(); - + window.addEventListener('storage', onStorageChange); return () => window.removeEventListener('storage', onStorageChange); - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return [state, setState]; diff --git a/vite.config.ts b/vite.config.ts index 49bdf04..f22e9be 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,7 +4,6 @@ import { dirname } from 'path'; import { fileURLToPath } from 'url'; import { defineConfig } from 'vite' import dts from 'vite-plugin-dts' -import topLevelAwait from "vite-plugin-top-level-await"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -12,7 +11,6 @@ const __dirname = dirname(__filename); export default defineConfig({ plugins: [ dts({ include: "lib", insertTypesEntry: true, }), - topLevelAwait({}), ], build: { copyPublicDir: false,