React query

From vultisig/vultisig-windows · View interactive version

React query is an AI agent skill from the GitHub repository vultisig/vultisig-windows. Guide for writing React Query hooks, mutation hooks, and query UI in this codebase. Use when creating or modifying useQuery/useMutation hooks, rendering query states, combining or transforming queries, invalidating caches, or working with `@lib/ui` query utilities.

How to use this skill

Skill file

React Query Patterns

Custom types and utilities live in @lib/ui (lib/ui/query/).

Query Hook

import { useQuery } from '@tanstack/react-query'

export const useSomeQuery = () => {
  const input = { id, network }

  return useQuery({
    queryKey: ['getSomething', input],
    queryFn: () => getSomething(input),
  })
}

Resolved Data Hook

When a parent renders children only after a query succeeds (via MatchQuery) and child components need to access the resolved data, provide a companion hook. Only create this hook when there are actual consumers -- knip will flag unused exports.

export const useSomeQuery = () => useQuery({ ... })

export const useSomeData = () => {
  const { data } = useSomeQuery()
  return ensurePresent(data, 'some query data')
}

Query UI Rendering

Use MatchQuery from @lib/ui/query/components/MatchQuery for loading/error/success states. Never write manual if (isLoading) / if (error) checks.

import { MatchQuery } from '@lib/ui/query/components/MatchQuery'

<MatchQuery
  value={query}
  pending={() => <Spinner />}
  error={(e) => <ErrorMessage error={e} />}
  success={(data) => <DataView data={data} />}
/>

All render props default to () => null. There is also an inactive prop for queries that haven't started.

Mutation Hook

import { useMutation } from '@tanstack/react-query'
import { useRefetchQueries } from '@lib/ui/query/hooks/useRefetchQueries'

export const useSomeMutation = () => {
  const refetchQueries = useRefetchQueries()

  return useMutation({
    mutationFn: async () => {
      // perform mutation
    },
    onSuccess: () => {
      refetchQueries(getTransactionsQueryKey({ ... }))
    },
  })
}

Utilities (`@lib/ui`)

Query option presets to spread into useQuery:

Hooks for composing queries:

Types:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.