Skip to content

How to deal with onSuccess or onError? #138

Answered by wobsoriano
NilsEvers asked this question in Q&A
Discussion options

You must be logged in to vote

How about doing something like this?

import { yourNotifFunc, doSomethingWithData } from './somewhere'

useQuery('todos', fetchTodoList, {
    onSuccess: (data) => {
        yourNotifFunc('success')
        doSomethingWithData(data)
    },
    onError: () => {
        yourNotifFunc('error')
    }
})

Also worth checking https://tkdodo.eu/blog/status-checks-in-react-query

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NilsEvers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants