Skip to content
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

Pass though queryKey on useQuery #62

Closed
jimthedev opened this issue Dec 5, 2019 · 4 comments
Closed

Pass though queryKey on useQuery #62

jimthedev opened this issue Dec 5, 2019 · 4 comments

Comments

@jimthedev
Copy link

Hi @tannerlinsley,

One thing that would be nice is to return the queryKey on the object returned from the useQuery hook.

Would you consider this?

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Dec 5, 2019 via email

@tannerlinsley
Copy link
Collaborator

Please reopen with a use case and we can discuss more :)

@jimthedev
Copy link
Author

Hey sorry, been running around a bit.

Anyhow, the use case is for someone who is creating a redistributable subey'ed queries in redistributable custom hooks. We want to return the final key so that it can be used for refetching. It is totally an optimization, pure and simple:

this works:

// definition
function useMyCustomHook (subkey) {
  const queryKey="apple" + subkey;
  return {
   queryKey,
    ...useQuery(queryKey);
}

// usage
const { queryKey } = useMyCustomHook('banana')

but this would be preferable:

// definition
function useMyCustomHook (subkey) {
  return useQuery('apple'+subkey)
}

// usage
const { queryKey } = useMyCustomHook('banana')

Cheers.

@jimthedev
Copy link
Author

@tannerlinsley Looks like I could open a new issue or you can open this one, whatever you prefer. Didn't want to dupe the issues board if you decide this isn't something you'd want.

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

No branches or pull requests

2 participants