Fixed key/value stuff

This commit is contained in:
Gregory Schier
2023-03-29 14:46:36 -07:00
parent 06ce7abfb9
commit 4b2c1b18a9
5 changed files with 41 additions and 21 deletions

View File

@@ -41,12 +41,14 @@ export function useKeyValue<T extends Object>({
const set = useCallback(
(value: ((v: T) => T) | T) => {
if (typeof value === 'function') {
mutate.mutate(value(query.data ?? defaultValue));
getKeyValue({ namespace, key, fallback: defaultValue }).then((kv) => {
mutate.mutate(value(kv));
});
} else {
mutate.mutate(value);
}
},
[query.data, defaultValue],
[defaultValue],
);
const reset = useCallback(() => mutate.mutate(defaultValue), [defaultValue]);