Skip to content
Discussion options

You must be logged in to vote

I think the default query function shines when the queryKey basically only gets an already pre-built url passed in, like in the docs. For anything else, I likely wouldn't use it, as I don't really see the advantage of having big switches inside one queryFn over having each query make its own network request.

That being said, the middle ground would likely be utilizing queryClient.setQueryDefaults to set a queryFn per query key "group", something like:

queryClient.setQueryDefaults(['user'], { queryFn: ({ queryKey: [_, params] }) => fetchUser(params) }
queryClient.setQueryDefaults(['post'], { queryFn: ({ queryKey: [_, params] }) => fetchPosts(params) }

the key ['user', { id: 1 }] would tri…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bglgwyng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants