Skip to content

Commit

Permalink
Merge pull request #2 from kamranasad7/v1.0.5
Browse files Browse the repository at this point in the history
V1.0.5
  • Loading branch information
kamranasad7 authored Apr 18, 2024
2 parents 2036851 + 273d84f commit c7741e4
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 193 deletions.
Binary file modified CHANGELOG.md
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/ReactiveStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ class Crypto {
}
}

const encryption = await Crypto.createInstance();
const encryption = Crypto.createInstance();
export { encryption };
10 changes: 5 additions & 5 deletions lib/hooks/useLsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const get = async <T>(key: string): Promise<T | null> => {
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 <T>(key: string, value: T | null): Promise<void> => {
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));
}
Expand All @@ -28,7 +28,7 @@ const useLsState = <T>(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(() => {
Expand All @@ -38,10 +38,10 @@ const useLsState = <T>(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];
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-reactive-storage",
"author": "kamranasad7",
"description": "An encrypted and reactive localstorage system for react using hooks like useState",
"version": "1.0.4",
"version": "1.0.5",
"private": false,
"keywords": [
"localstorage",
Expand Down Expand Up @@ -40,18 +40,17 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.11.30",
"@types/react": "^18.2.69",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@vitejs/plugin-react-swc": "^3.6.0",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.4.3",
"vite": "^5.2.6",
"vite-plugin-dts": "^3.7.3",
"vite-plugin-top-level-await": "^1.4.1"
"typescript": "^5.4.5",
"vite": "^5.2.9",
"vite-plugin-dts": "^3.8.3"
}
}
Loading

0 comments on commit c7741e4

Please sign in to comment.