Skip to content

Commit

Permalink
updated use hook to now allow pulling in the entire object
Browse files Browse the repository at this point in the history
  • Loading branch information
sghsri committed Apr 25, 2024
1 parent 63d36a8 commit 17af446
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension-toolkit",
"version": "0.0.71",
"version": "0.0.72",
"description": "A template for creating npm packages using TypeScript and VSCode",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
19 changes: 11 additions & 8 deletions src/storage/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,16 @@ function createStore<T>(
arguments.length === 2 ? defaultValue : key === null ? defaults : defaults[key]
);

const onChange = useCallback(({ key: k, newValue }: DataChange<T>) => {
if (key === null) {
setValue(prev => ({ ...prev, [k]: newValue } as any));
} else {
setValue(newValue as any);
}
}, []);
const onChange = useCallback(
({ key: k, newValue }: DataChange<T>) => {
if (key === null) {
setValue(prev => ({ ...prev, [k]: newValue } as any));
} else {
setValue(newValue as any);
}
},
[key, setValue]
);

useEffect(() => {
if (key === null) {
Expand All @@ -328,7 +331,7 @@ function createStore<T>(
store.unsubscribe(onChange as any);
};
}
}, []);
}, [key, onChange]);

const set = async newValue => {
if (key === null) {
Expand Down

1 comment on commit 17af446

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 9%
8.62% (27/313) 13.41% (11/82) 9.09% (7/77)

Please sign in to comment.