-
I know
import grocerRequest from './grocerConfig'
import { GetGrocerCampaignsResponse, getGrocerCampaignsResponseSchema } from './types'
export const getCampaigns = async (): Promise<GetGrocerCampaignsResponse> => {
const { data } = await grocerRequest.get<GetGrocerCampaignsResponse>('xxxxxx')
getGrocerCampaignsResponseSchema.parse(data)
return data
}
import { useQuery } from '@tanstack/react-query'
import { getCampaigns } from '../service/grocerRequests'
export const useGrocerCampaigns = () =>
useQuery({
queryKey: ['grocer', 'campaigns'],
queryFn: getCampaigns,
staleTime: 5 * 1000 // 5 seconds
})
const { data, refetch } = useGrocerCampaigns() I want to try refetch when user change bottom tabs or pull flatlist but not hard-refetch. I don't want users to spam servers |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Oct 2, 2023
Replies: 1 comment
-
you mean you want to ONLY refetch IF data is stale and NOT refetch if its FRESH. for that, you can use |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AuroPick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you mean you want to ONLY refetch IF data is stale and NOT refetch if its FRESH.
for that, you can use
queryClient.fetchQuery
and pass astaleTime
to it.