Can i update query keys from inside useQuery function #6695
-
|
i have a situation where i am polling an api using useQuery; i want to update query keys and axios functions params before the next api call is made based on data that i receive from the api. How can i do it? There is a problem if i use State in react; that sometimes it fetches data with old ids and also when state updates; as sometimes calculating new set of ids take time. Can i do this id modification from inside useQuery. The ids for fetchData call; i am getting from query keys; so if i can update them; i can do it Is there a way to modify queryKeys from useQuery hook itself. @TkDodo can you please give some idea on how accomplish this For Example: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Same applies here: |
Beta Was this translation helpful? Give feedback.
So, one way I'm seeing is to fire one query without refechInterval to just get the initial ids for notes, then do multiple useQuery (one for each noteId), potentially in
useQueries, and give each one their ownrefetchIntervaland stop polling once this specific note is done.This will make more requests one per noteId - batching them together would need to happen on a different layer, e.g. with a lib like batshit.
But I'm also questioning a bit the approach in general. Let's assume you have 5 noteIds, and you get back status
processingfor all of them. You refetch in an interval, next time, …