Skip to content

Commit

Permalink
0.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Aug 22, 2023
1 parent 0838cc4 commit 7045bff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export const LocalStoreProvider = ({
);
const [setValue] = useState(() => (value) => {
debug('setValue', { key, defaultValue: memoDefaultValue, value });
const _value = typeof(value) === 'function' ? value(stateRef.current) : value;
let current;
try {
current = JSON.parse(stateRef.current);
} catch(error) {
current = undefined;
}
const _value = typeof(value) === 'function' ? value(current) : value;
const json = stringify(_value);
localStorage.setItem(key, json);
_setValue(json);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/store",
"version": "0.0.24",
"version": "0.0.25",
"license": "Unlicense",
"author": "Ivan S Glazunov <[email protected]>",
"homepage": "https://github.com/deep-foundation/store",
Expand Down

0 comments on commit 7045bff

Please sign in to comment.