-
Is there a gotcha involved with the onSuccess callback in useMutate? I'm using useMutate to post a message to the backend. In Network in Chrome I get a response I'm expecting, but in the onSuccess callback data is still undefined. I looked around the net and it looks like I'm using it correctly but still no actual data in data.
The console.log(data) prints undefined and even the state doesn't seem to get updated with an actual id, only undefined. I'm using this code in a custom hook. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
The gotcha is that your mutation function doesn't return anything:
if a function doesn't return anything, it returns |
Beta Was this translation helpful? Give feedback.
-
damn this just got me good 😆 |
Beta Was this translation helpful? Give feedback.
-
I get this problem if I use invalidateQueries inside onSuccess. Is this the expected behavior?
If I remove the invalidateQueries then data is filled with data. |
Beta Was this translation helpful? Give feedback.
The gotcha is that your mutation function doesn't return anything:
if a function doesn't return anything, it returns
undefined
implicitly, which is what you'll then get. So you need to return the Promise from your data fetching function to react-query for it to work.