useCustom callback on success
How can I use onSuccess function when it will be deprecated. I would like to trigger a function when a successfull request has been done. I would love to do this without the need of an useEffect.
onSuccess function is a prop that can be used in various hooks and components in Refine to execute a function after a successful request. It is not mentioned in the extracts that onSuccess will be deprecated. Here are some examples of how you can use it:DeleteButton component, you can use onSuccess to execute a function after a successful delete request. Here's an example:useForm hook, you can use onSuccess to execute a function after a successful form submission. Here's an example:useDrawerForm hook, you can use onSuccess in deleteButtonProps and saveButtonProps to execute a function after a successful delete or save operation. Here's an example:onSuccess function is not deprecated according to the information provided in the extracts. If you have heard otherwise, I recommend checking the official Refine documentation or contacting their support for the most accurate information.onSuccessonSuccessonSuccessonSuccessonSuccessonSuccessDeleteButtonuseFormuseDrawerFormdeleteButtonPropssaveButtonPropsimport { DeleteButton } from "@refinedev/antd";
const MyDeleteComponent = () => {
return (
<DeleteButton
resourceNameOrRouteName="posts"
recordItemId="1"
onSuccess={(value) => {
console.log(value);
}}
/>
);
}; const { onFinish, mutationResult } = useForm({
onFinish: async (values) => {
// Your custom logic before submitting the form
const data = {
...values,
products: tableData,
finalPrice: finalPrice,
};
await onFinish(data);
},
onSuccess: (response) => {
console.log("Success response:", response);
},
onError: (error) => {
console.log("Error response:", error);
},
});const { deleteButtonProps } = useDrawerForm({
action: "delete",
});
deleteButtonProps.onSuccess();