Skip to content
Source
Sign inSign up
TanStack/query

Add support for event handlers? #15

Closedrostero1(GitHub profile, opens in a new tab) opened this issue 2 comments

Would it be beneficial to add support for on fetch (or state change) event handlers since useEffect can be delayed or not run at all?

Example,

const info = useQuery('todos', fetchTodoList, { onError: (error) => showToast(error) });
const [mutate, { data, isLoading, error }] = useMutation(login, { onSuccess: (data) => reduxDispatch({type: 'LOAD_PROFILE', data: data }) });

On the last example, we can probably handle this in the event that made the call to mutate:

const data = await mutate({ title })
reduxDispatch({type: 'LOAD_PROFILE', payload: data });
  1. The onError and related useQuery event handlers should be pretty easy to do. The mutate handler, I agree that it's simple enough just to rely on the promise of the mutate function. I think it's better control flow there tbh.

  2. 🎉 useQuery.onSuccess/onError added in version 0.3.2

  3. tannerlinsley closed this

Sign in to join this conversation.