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

Custom cache key #4

Closed
john-pc opened this issue Sep 17, 2019 · 4 comments
Closed

Custom cache key #4

john-pc opened this issue Sep 17, 2019 · 4 comments

Comments

@john-pc
Copy link

john-pc commented Sep 17, 2019

Hey Tanner, thank you for another amazing library.

I would like to suggest to add custom cache key from useQuery, since the query be can changed depending on the implementation, it would be very helpful to be able to control the cache key name

@tannerlinsley
Copy link
Collaborator

So instead of relying on the idempotency of the query for the cache keying, you want to override the ID it would be given by an arbitrary string?

@tannerlinsley
Copy link
Collaborator

If that's the case, then we would need to propagate the manual key to this location here: https://github.com/tannerlinsley/react-query/blob/master/src/index.js#L524. It would need to originate in the query options and get passed through a few functions to get there.

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Sep 23, 2019

Though not fully documented yet. You can now use a custom queryID option to override the generated queryID normally returned from the function, eg.

// You must memoize the query function. useQuery will still detect changes to the
// `query` reference and try to refetch if it changes
const queryFn = React.useCallback(() => axios.get('/todos'), [])

// Then just pass a `queryID` string:
useQuery(queryFn, { queryID: 'fetchTodos' })

@sithuhub
Copy link

#28

TkDodo referenced this issue in TkDodo/react-query Jun 5, 2021
lukesmurray added a commit to lukesmurray/query that referenced this issue Sep 9, 2022
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

3 participants