Refresh interval for useQuery

I am using wasp version 0.16.6. I would like to set refresh interval for useQuery to 5 seconds (so it refresh content of a page every 5 seconds). But I am not sure how to pass arguments to useQuery function. You can show me on this official example: https://wasp.sh/docs/tutorial/queries#invoking-the-query-on-the-frontend So this line needs to be updated with refresh interval somehow: const { data: tasks, isLoading, error } = useQuery(getTasks)
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Jarko Sunce | Calimero. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To set a refresh interval for a query using Wasp's useQuery, you can pass an options object as the third argument to useQuery. This options object is passed directly to react-query under the hood, so you can use react-query's options like refetchInterval. Here's how you can update your example to refresh the query every 5 seconds (5000 ms):
const { data: tasks, isLoading, error } = useQuery(getTasks, undefined, { refetchInterval: 5000 })
const { data: tasks, isLoading, error } = useQuery(getTasks, undefined, { refetchInterval: 5000 })
- The first argument is your query function (getTasks). - The second argument is for query arguments (undefined if you have none). - The third argument is the options object, where you set refetchInterval to 5000 milliseconds. This will make your query automatically refetch every 5 seconds. You can find more details about the useQuery hook and its options in the Wasp documentation: The useQuery Hook and Invoking the Query On the Frontend. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Jarko Sunce | Calimero, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Jarko Sunce | Calimero
That helped, you can mark it solved.

Did you find this page helpful?