Request and update as the server comes along
So, I have a scenario in which I have a list of currencies, like
["USD", "EUR", "BRL"]
etc, that has a dynamic size. My problem is that the API only allows for 5 calls per minute, so I need a 20s interval just to be safe.
Now, requesting every 20s is easy, but I can't wrap my head around how to have a React Query set up so I read from this array of currencies, and return one by one so I can render it in real time on the client. And then restart the cycle.
I've thought of many workarounds, but nothing that seems like a perfect solution. Does anyone have any idea on how I could do this?8 Replies
My current, but not very good, solution would be to make a hook that has a
while loop
in a useEffect
it that queries one by one every 20 seconds and then restarts.
But then what would be the point of the RQ here if I'd have to fetch this manually, since I couldn't use a hook inside the useEffect
Yeah I asked GPT about this and it gave me a useful info that I didn't think of: useing refetchInterval of 20s.
Aside from that, it also gave me a hint to use a cursor in the array in the useEffect.
If anyone has a better solution, let me know. I'll go with this one for nowhttps://tanstack.com/query/latest/docs/react/examples/react/auto-refetching
add 'refetchInterval' to query options ?
are you fucking kidding me, this is exactly what I needed
thank you
lol, you're welcome bro
what did you search to find it
I tried so many things man
literally went to their documentation and found it
it's very confusing at tanstack docs, I had to implement their version of tables - tanstack table - and it's even worse than query docs, but I found it useful to dig through their examples.
happy I could help
Yeah I was lost on my other ways to do it, thank you very much
no problem, hmu if you have more questions