You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have a useLazyGetRandomThingsQuery that returns 10 random things and can't return more due to performance. In the UI I want 100 of these random things so I need to fire 10 requests when user clicks the "Fetch" button as indicated below 👇
What I want to achieve:
Put all these 100 things from the 10 requests in the same cache, after each request, we append the results to the original cache instead of overwriting.
What actually happens
Only 1 request gets fired and data is always a 10 items array.
// endpoint def
getRandomThings:({query:()=>`api/get-random-posts`,merge: (currentCache,newData)=>[...currentCache, ...newData],// I suppose this probably won't help since all the requests share the same cache key anyway?forceRefetch: ()=>true,}),// RandomThings.jsxconst[getRandomThings,{ data }]=useLazyGetRandomThingsQuery();constonFetchClick=()=>{for(leti=0;i<10;i+=1){getRandomThings()}}return<buttononClick={onFetchClick}>Fetch</button>
Is there any way that I can cancel request duplication? Anything that I'm misunderstanding? Any other way people would approach this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose I have a
useLazyGetRandomThingsQuery
that returns 10 random things and can't return more due to performance. In the UI I want 100 of these random things so I need to fire 10 requests when user clicks the "Fetch" button as indicated below 👇What I want to achieve:
Put all these 100 things from the 10 requests in the same cache, after each request, we append the results to the original cache instead of overwriting.
What actually happens
Only 1 request gets fired and
data
is always a 10 items array.Is there any way that I can cancel request duplication? Anything that I'm misunderstanding? Any other way people would approach this?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions