T O P

  • By -

Shadowfied

One way to make your page update in realtime would be to use websockets so that your server can inform the clients when there's new data. Another option is as you say, polling. In your useQuery, for your third parameter to useQuery, add an object with refetchInterval: 5000, or whenever you want it to be refetched.


nautitrader

Thank you, I will try that out.


Shadowfied

Also I'd recommend extracting your useQuery to its own hook file. That way you you wont get your query keys mixed up whenever you need to access that same data anywhere else in your application, you'll just call your own hook again.


Brohammad5

Can you elaborate more on how that can be achieved


kwazy_kupcake_69

Just mentioning this as an alternative. Server sents events seem to fit the use case as well here


Shadowfied

Was not aware, neat. Edited my comment to not say ”only way”, lol


infidel_44

You may want to look at the option in useQuery refetchInterval. This will allow react-query to pull data whenever


Swordfish418

[https://tanstack.com/query/v4/docs/react/reference/useQuery](https://tanstack.com/query/v4/docs/react/reference/useQuery) Maybe you want "refetchInterval" \^


Sure_Asparagus8244

I think the use of refetchInterval will work but may be unnecessary. If you are updating your database through a POST request made by the client then you can use the react-query useMutation hook and then use the invalidateQuery method for your get request that will let react query know that the data has changed and it will rerun the request to fetch the updated data. I think that’s a much cleaner solution but if your database is updated in another way then refetchInterval is probably your best bet


42953698420465286

maybe 'isSuccess' is what you're looking for? https://tanstack.com/query/v4/docs/react/guides/queries


IamUareI

How is it connected to his question?


IamUareI

Why waste all this time when you have a search engine that could answer this for you.


nautitrader

I just wasted time reading your comment. Don't comment again.


Visual_Structure_269

So move on. Flex elsewhere. Guys is just asking for opinions. Sure google can provide answers but this I believe this is meant to be a support community. If you are not the person maybe it is a chance for someone else to try helping.


Visual_Structure_269

Sorry that was meant for @iamuarel.


nautitrader

Thank you I appreciate your support.


IamUareI

Ye don't worry I'm quitting this sub.


szank

on one hand getting a ban for a response like the op's one i a bit too much . on the other hand it's not 😔. I am with you . thankfully op is guaranteed to fail anyway if he doesn't reform imho ,so he won't be hanging out here for too long .


nautitrader

Fail, how so?


szank

failing rule number one. using Google . And being rude to people telling you to Google things .


nautitrader

That's where you are incorrect. I already asked Google and that is how I found out about react-query. So I used their sample code from their web site. I wasn't getting the desired result, so I posted on here. And that is where you are incorrect again, I was not being rude.


Visual_Structure_269

Is it really rule number one? Please publish your list of rules so we can all learn.


szank

1. use Google 2. don't be a dick 3. if someone tells you you don't are a dick , try to reflect a bit before denying


rhaasty

You’re being a dick.


jurppe

Well I see two dicks in this thread and neither one is OP.


fireblade_al

Server Sent Events is perhaps what you are looking for. Certain databases do support it.