Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for event handlers? #15

Closed
rostero1 opened this issue Nov 6, 2019 · 2 comments
Closed

Add support for event handlers? #15

rostero1 opened this issue Nov 6, 2019 · 2 comments

Comments

@rostero1
Copy link

rostero1 commented Nov 6, 2019

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 });
@tannerlinsley
Copy link
Collaborator

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.

@tannerlinsley
Copy link
Collaborator

🎉 useQuery.onSuccess/onError added in version 0.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants