Skip to content

refactor: Use queryOptions API to clean up useApiQuery hook definitions#2566

Merged
david-crespo merged 1 commit intomainfrom
api-query-options-2
Nov 21, 2024
Merged

refactor: Use queryOptions API to clean up useApiQuery hook definitions#2566
david-crespo merged 1 commit intomainfrom
api-query-options-2

Conversation

@david-crespo
Copy link
Collaborator

@david-crespo david-crespo commented Nov 20, 2024

Was inspired.

image

https://x.com/TkDodo/status/1857764199813861829

The goal here is to keep this change very minimal and show that nothing changes in order to enable a more interesting followup change improving QueryTable. But it makes some other interesting things possible (which I don't do in this PR):

export const apiq = getApiQueryOptions(api.methods)
- apiQueryClient.prefetchQuery('projectList', { query: { limit: PAGE_SIZE } })
- useApiQuery('projectList', { query: { limit: PAGE_SIZE } })

+ const projectListOptions = apiq('projectList', { query: { limit: PAGE_SIZE } })
+ 
+ queryClient.prefetchQuery(projectListOptions)
+ useQuery(projectListOptions)

See also tRPC’s RFC to do something very similar in their generated client.

@vercel
Copy link

vercel bot commented Nov 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Nov 20, 2024 6:21pm

@david-crespo david-crespo merged commit 67033a3 into main Nov 21, 2024
@david-crespo david-crespo deleted the api-query-options-2 branch November 21, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant