other-emerald
other-emerald9mo ago

How to pass a parameter in useCustomMutation hook?

I want to pass certain parameter in url endpoint while performing a custom mutation. For example: I want to post a request with a url endpoint as /posts/?category=published, to get a data using that url we have a config.filters in useCustom hook but I am not sure if the mutation hook have the same feature.
2 Replies
kapa.ai
kapa.ai9mo ago
Hi @dipbazz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, the useCustomMutation hook allows you to specify the URL endpoint for your mutation request. You can pass parameters in the URL endpoint as well. Here's an example:
const { mutate } = useCustomMutation();

mutate({
url: "/posts/?category=published",
method: "post",
values: {
title: "New Post",
},
});
const { mutate } = useCustomMutation();

mutate({
url: "/posts/?category=published",
method: "post",
values: {
title: "New Post",
},
});
In this example, the url parameter is used to specify the URL endpoint of the mutation request. You can include any parameters you need in this URL. However, unlike the useCustom hook, the useCustomMutation hook does not have a config.filters property. If you need to include filters in your mutation request, you would need to include them in the values property or directly in the URL as shown above. For more information, refer to the useCustomMutation documentation (https://refine.dev/docs/api-reference/core/hooks/data/useCustomMutation/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@494653850632978472> kapa.ai is still learning and improving, please let us know how it did by reacting below