From 17af4461b3279f95585fc48ccbad6fe372a89bbf Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Wed, 24 Apr 2024 23:13:49 -0500 Subject: [PATCH] updated use hook to now allow pulling in the entire object --- package.json | 2 +- src/storage/createStore.ts | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index ade42fa..dbc964d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/storage/createStore.ts b/src/storage/createStore.ts index a11c15e..020a7cf 100644 --- a/src/storage/createStore.ts +++ b/src/storage/createStore.ts @@ -306,13 +306,16 @@ function createStore( arguments.length === 2 ? defaultValue : key === null ? defaults : defaults[key] ); - const onChange = useCallback(({ key: k, newValue }: DataChange) => { - if (key === null) { - setValue(prev => ({ ...prev, [k]: newValue } as any)); - } else { - setValue(newValue as any); - } - }, []); + const onChange = useCallback( + ({ key: k, newValue }: DataChange) => { + if (key === null) { + setValue(prev => ({ ...prev, [k]: newValue } as any)); + } else { + setValue(newValue as any); + } + }, + [key, setValue] + ); useEffect(() => { if (key === null) { @@ -328,7 +331,7 @@ function createStore( store.unsubscribe(onChange as any); }; } - }, []); + }, [key, onChange]); const set = async newValue => { if (key === null) {