diff --git a/src/data-fetching-store.ts b/src/data-fetching-store.ts index 0b34aa1e..a46e0472 100644 --- a/src/data-fetching-store.ts +++ b/src/data-fetching-store.ts @@ -219,7 +219,10 @@ export const useDataFetchingStore = defineStore('PiniaColada', () => { } } - function setEntryData(key: UseQueryKey, data: TResult) { + function setEntryData( + key: UseQueryKey, + data: TResult | ((data: Ref) => void) + ) { const entry = entryStateRegistry.get(key) as | UseQueryStateEntry | undefined @@ -227,7 +230,12 @@ export const useDataFetchingStore = defineStore('PiniaColada', () => { return } - entry.data.value = data + if (typeof data === 'function') { + // the remaining type is TResult & Fn, so we need a cast + ;(data as (data: Ref) => void)(entry.data) + } else { + entry.data.value = data + } // TODO: complete and test entry.error.value = null }