Skip to content

useIsLoading ​

"Is anything of these resources busy?", across the whole app: true while any query or mutation whose resourceKey starts with one of the given prefixes is in flight. For a layout-level spinner that is not tied to one resource.

Quickstart ​

ts
import { useIsLoading } from '@guebbit/vue-toolkit'

// in a layout component's setup()
const isAccountAreaLoading = useIsLoading(['account', 'cart'])
const isAnythingLoading = useIsLoading()
vue
<progress v-if="isAccountAreaLoading" aria-label="Loading" />

API ​

useIsLoading(prefixes?, queryClient?) returns ComputedRef<boolean>.

ParameterTypeDefaultPurpose
prefixesstring[][]resourceKey prefixes to match. Empty: every query and mutation on the client.
queryClientQueryClientthe one VueQueryPlugin providesThe client to watch. Pass it where there is no injection context (a plain effectScope, a test).

How it matches ​

  • It reads TanStack's own counters (useIsFetching + useIsMutating), filtered by the first segment of each query or mutation key: a resource's resourceKey.
  • A prefix matches by string start: 'account' matches 'account' and 'accountProfile'. Name resources with that in mind.
  • It sees every resource on the client, whether this component uses it or not, including queries and mutations you make yourself with keys starting with a matching string.
  • It is already a ComputedRef: call it once in setup(), not inside a computed.

Compared with the other loading flags ​

QuestionUse
Is this resource busy? Is this one call of it busy?The resource's own loading / isLoading(key), which matches the call's key by segment prefix.
Is any resource under these prefixes busy?useIsLoading(prefixes)
Is my own, non-request work busy (a wizard step, a computation)?useCoreStore, which uses the same string-prefix rule on its flag names.

Gotchas ​

  • Needs an effect scope. Like every TanStack composable it subscribes to the client and unsubscribes when the surrounding scope (component, Pinia setup store, effectScope) stops. Created outside any scope, that subscription is never released.
  • Needs an injection context for the default client. Outside a component's setup() or a Pinia setup store, pass queryClient explicitly.

See also ​

Documentation for @guebbit/vue-toolkit v5.2.0. Released under the AGPL-3.0 license.