onMutationSuccess from useForm returns undefined for data

Trying to access the created object from a useForm, however the onMutationSuccess always returns undefined for the data object
7 Replies
kapa.ai
kapa.ai6mo ago
Hi @ziyad. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The onMutationSuccess callback function in useForm should return the data from a successful mutation. It's possible that the issue you're experiencing is due to the action not being properly set. The onMutationSuccess function receives the returned value from either useCreate or useUpdate, depending on the action set in useForm. Here's an example of how to use onMutationSuccess:
useForm({
onMutationSuccess: (data, variables, context, isAutoSave) => {
console.log({ data, variables, context, isAutoSave });
},
});
useForm({
onMutationSuccess: (data, variables, context, isAutoSave) => {
console.log({ data, variables, context, isAutoSave });
},
});
(Source: Refine Documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form#onmutationsuccess)) If you're still getting undefined, it might be worth checking if the data is being returned from the data provider create. If the data is being returned correctly, you might need to specify the action as edit or create for it to work properly. If you're still having issues, it might be a good idea to check if there's a similar issue on the Refine GitHub page (https://github.com/refinedev/refine/issues). If you can't find a similar issue, consider opening a new one with a detailed description of your problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6mo ago
<@954404142510645268> kapa.ai is still learning and improving, please let us know how it did by reacting below
metropolitan-bronze
metropolitan-bronze6mo ago
I think I implemented it yet I am getting the same issue. here's my code. what am i missing "use client"; import { Create, useForm } from "@refinedev/antd"; import { Form, Input } from "antd"; import { useCreate } from "@refinedev/core"; import { ITemplate } from "@utility/interfaces"; export default function BlogPostCreate() { const { mutate } = useCreate(); const { formProps, saveButtonProps } = useForm({ onMutationSuccess: (data, variables, context, isAutoSave) => { console.log({ data, variables, context, isAutoSave }); }, }); return ( <Create saveButtonProps={saveButtonProps}> <Form {...formProps} layout="vertical"> <Form.Item label={"Title"} name={["title"]} rules={[ { required: true, }, ]} > <Input /> </Form.Item> </Form> </Create> ); } @kapa.ai
kapa.ai
kapa.ai6mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @ziyad, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
metropolitan-bronze
metropolitan-bronze6mo ago
onMutationSuccess does not return data object to the callback I am passing it. What could be the issue? @kapa.ai
kapa.ai
kapa.ai6mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The onMutationSuccess callback function in useForm should return the data from a successful mutation. However, if it's not returning the data as expected, there could be a few reasons for this: 1. Mutation Mode: The mutation mode might be set to optimistic instead of pessimistic (which is the default). In optimistic mode, the response in the onSuccess method will be undefined. Make sure you're using the pessimistic mutation mode to get the response in the onSuccess method. (Source: Discord Support Thread (https://discord.com/channels/837692625737613362/1142556528369479790)) 2. Data Provider: The capability to return data depends on your data provider. In custom ones, you can use the meta property to pass additional data to the data provider and inside the data provider, you can use that value to select or not after create. For example, @refinedev/supabase has a meta.select that you can use in useCreate and other similar hooks to do a select query after the mutation. (Source: Discord Support Thread (https://discord.com/channels/837692625737613362/1142556528369479790)) 3. Bug: There might be a bug in the version of Refine you're using. For example, there was a bug reported where useStepsForm mutation did not return a result. The form successfully passed the data to the server, but returned no results. The issue was seen in @pankod/refine-antd version ^3.41.0 and @pankod/refine-core version ^3.69.0. (Source: GitHub Issue (https://github.com/refinedev/refine/issues/2462)) If you're still having issues, consider checking if there's a similar issue on the Refine GitHub page (https://github.com/refinedev/refine/issues). If you can't find a similar issue, consider opening a new one with a detailed description of your problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6mo ago
<@954404142510645268> kapa.ai is still learning and improving, please let us know how it did by reacting below