From 7b38a05c3611c7a09423ef73db7e98e365ea5ce9 Mon Sep 17 00:00:00 2001 From: Carl Chen Date: Tue, 5 Aug 2025 03:54:46 +0800 Subject: [PATCH] refactor: replace `Ref` with `ShallowRef` for improved state management --- src/core/createQuery.ts | 4 ++-- src/core/types.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/createQuery.ts b/src/core/createQuery.ts index a30d8e3..2fd1176 100644 --- a/src/core/createQuery.ts +++ b/src/core/createQuery.ts @@ -1,4 +1,4 @@ -import type { Ref } from 'vue-demi'; +import type { Ref, ShallowRef } from 'vue-demi'; import { ref, shallowRef } from 'vue-demi'; import type { @@ -45,7 +45,7 @@ const createQuery = ( const { initialData, onSuccess, onError, onBefore, onAfter } = config; const loading = ref(initialState?.loading ?? false); - const data = shallowRef(initialState?.data ?? initialData) as Ref; + const data = shallowRef(initialState?.data ?? initialData) as ShallowRef; const error = shallowRef(initialState?.error); const params = ref(initialState?.params) as Ref

; const plugins = ref([]) as Query['plugins']; diff --git a/src/core/types.ts b/src/core/types.ts index be4acf5..831a785 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -1,6 +1,6 @@ /* istanbul ignore next */ -import type { Ref, WatchSource } from 'vue-demi'; +import type { Ref, ShallowRef, WatchSource } from 'vue-demi'; import type { PaginationExtendsOption } from '../usePagination'; import type { CacheData } from './utils/cache'; @@ -14,13 +14,13 @@ export interface Mutate extends MutateData, MutateFunction {} export type State = { loading: Ref; - data: Ref; - error: Ref; + data: ShallowRef; + error: ShallowRef; params: Ref

; }; export interface Query extends State { - status: Ref<'pending' | 'settled'>; + status: ShallowRef<'pending' | 'settled'>; context: FunctionContext; plugins: Ref>[]>; }