Custom Query Factory Functions #3964
Unanswered
TClark1011
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think it would be great if there were "factory functions" that helped developers compose custom hooks that can be conveniently re-used.
createCustomQueryHook
Create a custom query hook. The query key and query function would be passed into this function so they would not have to be specified every time the hook is used. You can also specify options in this functions, and option overrides could also be applied when the custom hook is called.
When specifying the options/query key , they can be provided as static values, however if the query function takes parameters, then you can provide a function that will return the query keys/options.
This function would then return an object with the fields
useCustomQuery
which would contain the newly created hook, and anoptions
field which would contain the options used to create that hook. The reason for providing the hook and options in an object instead of only returning the hook itself, is that by returning the options we can then re-use those options insideuseQueries
. If the options of the hook were created with a function, then theoptions
field would be a function that takes the same parameters as the query itself and then returns the options.extendCustomQueryHook
Similar to
createCustomQueryHook
, except you pass a custom query hook as the first parameter and option overrides as the second parameter.Mutations
You would also include mutation equivalents
createCustomMutationHook
extendCustomMutationHook
Examples
Hook With Parameters
Without Parameters
Beta Was this translation helpful? Give feedback.
All reactions