refresh in useQueries cause infinite rerender
Do you know why
useAllData causes a re-render, whereas useOneData data works normally?
10 Replies
eastern-cyan•12mo ago
@Hugo Levet Huge guess, but, does the request take more than 100ms?
Also, may I ask why you use 2 fetch functions inside of
queryFn maybe this can be resolved in another waysensitive-blueOP•12mo ago
Yes but you can replace
const fetch1 = "data fetch 1"; by const fetch1 = await fetch('<some_url>'); so fetch time is not a problem right?
Yes, probably but the answer is more about why useQuery and useQueries don't works same?eastern-cyan•12mo ago
my point is that
fetch1 does not have time to finish and you call refetch, but I am not sure if the request gets thrown away and everything restarts, hence causing an infinite loop
I asked this because, this approach seems error prone. I want to know what you are trying to achieve so I could propose another method.sensitive-blueOP•12mo ago
oh yes I see, I checked but no error appears, I will add a try catch to be sure
eastern-cyan•12mo ago
I mean, there is no error that happens
it might just throw away the request and try again from 0
then again and again
but as I said, I am not sure, what you are doing (
refetch inside of queryFn) is not a very common casesensitive-blueOP•12mo ago
ok thanks, fetch1 is fast to response but it send old data not fresh. fetch2 is more slow than fetch1 but data is up to date.
My app first show old data and when updated data is getting show fresh data
hum strange but ok
eastern-cyan•12mo ago
i mean, you are telling it to refetch, before it even got to have data in the first place
sensitive-blueOP•12mo ago
Do you have a suggestion for my use case?
oh yes ok, It's okay I understood 😅
eastern-cyan•12mo ago
- I'd use 2
useQueries somehow, with different queryKeys, maybe add fast: true to the first one and disable caching and refetching for it, then use the response of this one as the placeholderData for the second slow one.
- Or you could try fetch1.then(() => refetch()) instead of the setTimeout, might also want to use keepPreviousDatasensitive-blueOP•12mo ago
ok, thanks for you help I will try a solution like that
I use first one and it's work thanks a lot