diff --git a/src-web/components/App.tsx b/src-web/components/App.tsx index 81717ba2..33ba6205 100644 --- a/src-web/components/App.tsx +++ b/src-web/components/App.tsx @@ -1,5 +1,6 @@ import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import { persistQueryClient } from '@tanstack/react-query-persist-client'; import { invoke } from '@tauri-apps/api'; import { listen } from '@tauri-apps/api/event'; @@ -172,7 +173,7 @@ export function App() { - {/**/} + diff --git a/src-web/hooks/useKeyValue.ts b/src-web/hooks/useKeyValue.ts index 33aa665b..3b41bfa6 100644 --- a/src-web/hooks/useKeyValue.ts +++ b/src-web/hooks/useKeyValue.ts @@ -1,4 +1,4 @@ -import { useMutation, useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useCallback } from 'react'; import { buildKeyValueKey, getKeyValue, setKeyValue } from '../lib/keyValueStore'; @@ -24,6 +24,7 @@ export function useKeyValue({ key: string | string[]; defaultValue: T; }) { + const queryClient = useQueryClient(); const query = useQuery({ queryKey: keyValueQueryKey({ namespace, key }), queryFn: async () => getKeyValue({ namespace, key, fallback: defaultValue }), @@ -31,6 +32,10 @@ export function useKeyValue({ const mutate = useMutation({ mutationFn: (value) => setKeyValue({ namespace, key, value }), + onMutate: (value) => { + // k/v should be as fast as possible, so optimistically update the cache + queryClient.setQueryData(keyValueQueryKey({ namespace, key }), value); + }, }); const set = useCallback(