Skip to content

Is there a way to configure the provider staleTime based on URL? #1293

Answered by TkDodo
mwmcode asked this question in Ideas
Discussion options

You must be logged in to vote

I don't think so, but you could get away with a custom hook, something like that:

const queryApiReference = (url) => axios.get(`/api/reference/${url}`)

const useApiReferenceQuery = (key, url, options) =>
    useQuery(['apiReference', ...key], () => queryApiReference(url), { ...options, staleTime: Infinity }

you could also pass the whole url and set a different staleTime depending on url.startsWith to make it even more generic or so ...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mwmcode
Comment options

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