Skip to content

Custom Hook #8721

Feb 28, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I see a couple of issues with this hook:

  • you pass in givenOptions, but they don’t become part of the result. That means I an pass in an additional option like staleTime, and it will be ignored

  • low-level abstractions like this are usually much more complex because UseQueryOptions has 4 generics on type-level. Without those, you can e.g. never use the select option

  • it also means you can never get type inference, as you always have to provide the type for the result on every call-side: useFetchData<Array<Todo>>({ queryKey: ['api', 'todos'] })

  • the method isn’t part of the key, so changing methods from the call-side will result in different requests that will share the same cache, and …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hossein-jorfi
Comment options

Answer selected by hossein-jorfi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants