W
Wasp2w ago
XMDim

usequery wasp on success

usequery wasp on success
2 Replies
MEE6
MEE62w ago
Wohooo @XMDim, you just became a Waspeteer level 1!
kapa.ai
kapa.ai2w ago
Hi @XMDim. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Wasp’s useQuery hook is a wrapper around react-query’s useQuery, and it supports an options object as the third argument. You can use this options object to specify an onSuccess callback, just like you would with react-query. Here’s how you can use the onSuccess option with Wasp’s useQuery:
import { useQuery, getTasks } from 'wasp/client/operations'

const MyComponent = () => {
const { data, isLoading, error } = useQuery(
getTasks,
undefined, // or your query arguments
{
onSuccess: (data) => {
// Your success logic here
console.log('Query succeeded!', data)
}
}
)

// ...rest of your component
}
import { useQuery, getTasks } from 'wasp/client/operations'

const MyComponent = () => {
const { data, isLoading, error } = useQuery(
getTasks,
undefined, // or your query arguments
{
onSuccess: (data) => {
// Your success logic here
console.log('Query succeeded!', data)
}
}
)

// ...rest of your component
}
This works because Wasp passes the options object directly to react-query’s useQuery under the hood, as described in the documentation:
Wasp's useQuery hook accepts three arguments: ... options: A react-query options object. Use this to change the default behavior for this particular Query.
The useQuery Hook – API Reference So, you can use onSuccess, onError, and other react-query options with Wasp’s useQuery. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @XMDim, 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?

Did you find this page helpful?