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
deforestor
deforestorOP2y ago
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 now
deforestor
deforestorOP2y ago
are you fucking kidding me, this is exactly what I needed thank you
bakdaddy
bakdaddy2y ago
lol, you're welcome bro
deforestor
deforestorOP2y ago
what did you search to find it I tried so many things man
bakdaddy
bakdaddy2y ago
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
deforestor
deforestorOP2y ago
Yeah I was lost on my other ways to do it, thank you very much
bakdaddy
bakdaddy2y ago
no problem, hmu if you have more questions
Want results from more Discord servers?
Add your server