* feat: move notion docs to standards folder * fix: remove skills mention (automatic now)
1.7 KiB
1.7 KiB
name, description, argument-hint
| name | description | argument-hint |
|---|---|---|
| tanstack-query | Convert a page or component from useAsyncData/manual ref patterns to TanStack Query for server state management. Use when migrating data fetching to useQuery/useMutation, adding cache invalidation, or replacing useAsyncData with TanStack Query. | <path-to-file> |
Refer to the standard: @standards/frontend/FETCHING_DATA.md
Steps
- Read the target file at
$ARGUMENTSand identify all data-fetching patterns:useAsyncData,useFetch, manualref()+await, oronMountedfetch calls. - Read the standard above for the query/mutation patterns, query key conventions, and optimistic update approach.
- Convert queries:
- Replace
useAsyncData/useFetch/ manual fetches withuseQuery. - Use the
api-clientviainjectModrinthClient()for thequeryFn. - Design query keys with the
['resource', 'version', ...params]convention. - Use
computedquery keys for reactive parameters. - Use the
enabledoption for conditional queries that depend on other data.
- Replace
- Convert mutations:
- Replace manual
try/catch+refpatterns withuseMutation. - Add
onSuccesshandlers that invalidate or update related query caches. - Consider optimistic updates for UI-critical mutations (follow the pattern in the standard).
- Replace manual
- Clean up:
- Remove manual loading/error
ref()s that are now handled by TanStack Query's return values (isPending,isError,error). - Remove manual
onMountedfetch calls. - Ensure SSR compatibility — queries in Nuxt pages are automatically awaited during SSR.
- Remove manual loading/error
- Verify the page still renders correctly and that cache invalidation triggers re-fetches where expected.