-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defineQuery helper function #37
Comments
In an ideal world we could even have a toggable option to automatically generate the queryKey based on the queryFn parameters, although I'm not sure how feasable that might be..
|
I think I tried a similar concept while developing v1, but I had no luck |
I think that's a great idea @codebycarlos! It'd be awesome if you wanna have a take on implementing this. The only thing I would change is injecting the const users = createQueryKeys('users', defineQuery => {
byId: ({id}) => defineQuery({ id }, api.getUser),
loggedIn: ({id}) => defineQuery({ id }, api.getLoggedInUsers),
active: ({id}) => defineQuery({ id }, api.getActiveUsers),
... |
As I start to use this library, I noticed the following pattern coming up quite a bit..
One way to avoid this is with a helper function that takes in a key, and defines that as the parameters for the query function (1-1 relationship). Something like this (defineQuery or querify):
The end result is:
The nice thing about including this as a helper function is you don't have to force that particular style and users can opt-in as needed. Similar to #18.
The text was updated successfully, but these errors were encountered: