Steps
- Read the target file at
$ARGUMENTSand identify all data-fetching patterns:useAsyncData,useFetch, manualref()+await, oronMountedfetch calls. - Define query boundaries: use stable hierarchical keys, preserve reactive parameters, and decide whether mutation feedback needs an optimistic update.
- 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.
- 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. - Preserve the target surface's lifecycle behavior and avoid introducing duplicate initial requests.
- Remove manual loading/error
- Verify the page still renders correctly and that cache invalidation triggers re-fetches where expected.