T
TanStack3y ago
conscious-sapphire

Query isn't refetching properly with invalidateQueries?

Hi all, I have an analytics application which refetches data every time the user updates the date range. The payloads are really small so the UX isn't actually all too bad when it does work, and this is the approach we're taking. I want to refetch data every time this is updated, and here is the approach I am taking: const queryAnalytics = useQuery(['analytics'], ()=> getAnalytics(dateRange?.startDate.toISOString(), dateRange?.endDate.toISOString(), props.selectedRestaurant.id), {enabled: props.loadAnalytics}) Then, inside of a useEffect I have my invalidate queries function:
useEffect(()=>{
queryClient.invalidateQueries(['analytics'])
},[dateRange, props.selectedRestaurant])
useEffect(()=>{
queryClient.invalidateQueries(['analytics'])
},[dateRange, props.selectedRestaurant])
However this isn't working as expected, and inside of the devtools isn't even getting any new data. I've submitted a video that shows me playing around with the app. FOR THE PURPOSES OF THE VIDEO, THE NUMBERS ON SCREEN SHOULD NOT UPDATE -- that part hasn't been implemented yet, I know that won't work. I do know for sure that Black Oak Bar and Grill when clicked should have data, it works in controlled circumstances and shows 76 items there. All the other should have zero. When I click on black oak, there should be data and again I know it does under controlled circumstances. I know I must be missing something. Thanks so much!
3 Replies
conscious-sapphire
conscious-sapphireOP3y ago
PS: auto refetch just went off and here is what I got back
No description
conscious-sapphire
conscious-sapphireOP3y ago
that is what i want to see for the restaurant that have orders it appears to be some sort of problem with the variables being passed into the API call by the way, its like its not trying the API call with the new data okay, yeah so the actual problem is I need to put new variables into the query function when I invalidate the query, how can I do that? when the query auto-refetches it passes in the variable but I am not keeping this thread open for context but im starting a new thread that better describes my problem ##
unwilling-turquoise
unwilling-turquoise3y ago
I’ve answered your question in the other thread :reactquery:

Did you find this page helpful?