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

Can I call both of onSuccess function in trigger options and useSWRMutation options? #2934

Open
yinsang opened this issue Apr 9, 2024 · 0 comments

Comments

@yinsang
Copy link

yinsang commented Apr 9, 2024

Bug report

Description / Observed Behavior

I used to use react-query ,mutation onSuccess will call useMutation's onSuccess firstly, and call mutate onSuccess secondly.
see here https://tanstack.com/query/v4/docs/framework/react/guides/mutations#consecutive-mutations

useMutation({
  mutationFn: addTodo,
  onSuccess: (data, variables, context) => {
    // I will fire first
  },
  onError: (error, variables, context) => {
    // I will fire first
  },
  onSettled: (data, error, variables, context) => {
    // I will fire first
  },
})

mutate(todo, {
  onSuccess: (data, variables, context) => {
    // I will fire second!
  },
  onError: (error, variables, context) => {
    // I will fire second!
  },
  onSettled: (data, error, variables, context) => {
    // I will fire second!
  },
})

What kind of issues did you encounter with SWR?
swr onSuccess in trigger will override useSWRMutation's onSuccess, make onSuccess's common logic is hard to reuse
see source code here , mergeObjects will use opts's onSuccess

            const options = mergeObjects(mergeObjects({
                populateCache: false,
                throwOnError: true
            }, configRef.current), opts);

Expected Behavior

How did you expect SWR to behave here?
Will swr support onSucess both in trigger options and useSWRMutation options?
Besides, onSuccess override is missing description in Doc.

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

1 participant