Get response from onCreate mutate
I want to create a resource item in my backend, so I thought I would use useCreate instead of a regular post request, however I want to now be able to read the response of this request.
9 Replies
Hi @BlackBearFTW. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
mutate
function from useCreate
returns a promise that resolves with the result of the mutation. You can use this to read the response of the request. Here's how you can do it:
In the code above, response
will contain the result of the mutation. If the mutation is successful, response
will contain the data returned by the server. If the mutation fails, the promise will be rejected and the catch
block will be executed.
For more information, you can refer to the useCreate documentation (https://refine.dev/docs/data/hooks/use-create/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@490961337896402944> kapa.ai is still learning and improving, please let us know how it did by reacting below
other-emerald•6mo ago
@kapa.ai that doesn't work
Let me check the knowledge base for you. One moment! :books:
other-emerald•6mo ago
----------------------
I'm sorry to hear that the solution didn't work for you. Unfortunately, based on the information provided in the knowledge sources, I can't provide a more specific solution.
The
useCreate
hook from Refine should return a mutate
function that can be used to perform the create operation and it should return a Promise that resolves with the server's response. If this isn't working as expected, it might be due to a variety of factors such as network issues, server configuration, or a bug in Refine.
I would recommend checking the network tab in your browser's developer tools to see if the request is being sent and what response is being returned. If the request is being sent and a response is being returned, then the issue might be with how you're trying to read the response.
If you're still having issues, you might want to consider reaching out to the Refine community on Discord (https://discord.com/invite/refine) or opening an issue on the Refine GitHub repository (https://github.com/pankod/refine/issues).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@490961337896402944> kapa.ai is still learning and improving, please let us know how it did by reacting below
other-emerald•6mo ago
Hello @BlackBearFTW , you can use onSuccess
other-emerald•6mo ago
Thank you