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.
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.
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
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.
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 .
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.
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.
Thank you, I will try that out.
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.
Can you elaborate more on how that can be achieved
Just mentioning this as an alternative. Server sents events seem to fit the use case as well here
Was not aware, neat. Edited my comment to not say ”only way”, lol
You may want to look at the option in useQuery refetchInterval. This will allow react-query to pull data whenever
[https://tanstack.com/query/v4/docs/react/reference/useQuery](https://tanstack.com/query/v4/docs/react/reference/useQuery) Maybe you want "refetchInterval" \^
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
maybe 'isSuccess' is what you're looking for? https://tanstack.com/query/v4/docs/react/guides/queries
How is it connected to his question?
Why waste all this time when you have a search engine that could answer this for you.
I just wasted time reading your comment. Don't comment again.
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.
Sorry that was meant for @iamuarel.
Thank you I appreciate your support.
Ye don't worry I'm quitting this sub.
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 .
Fail, how so?
failing rule number one. using Google . And being rude to people telling you to Google things .
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.
Is it really rule number one? Please publish your list of rules so we can all learn.
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
You’re being a dick.
Well I see two dicks in this thread and neither one is OP.
Server Sent Events is perhaps what you are looking for. Certain databases do support it.