quickest-silver
quickest-silver2mo ago

useCustom on button click & declaration of multiple custom methods

How to use useCustom if I want to sent request on button click? Also how can I declare multiple custom requests in one provider?
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @Russ Salad. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To send a request on a button click using useCustom, you can use the mutate function provided by the useCustom hook. However, based on the information provided in the knowledge sources, the mutate function is not directly available in the useCustom hook. You might need to use the useCustomMutation hook for this purpose, but it doesn't support get requests. For declaring multiple custom requests in one provider, you can define multiple methods inside the custom method of your data provider. The custom method is an optional method that can be added to handle requests with custom parameters like URL, CRUD methods, and configurations. It's useful if you have non-standard REST API endpoints or want to make a connection with external resources. Refine will consume this method using the useCustom data hook. Here is an example of how you can define the custom method:
custom: async ({
url,
method,
filters,
sorters,
payload,
query,
headers,
meta,
}) => {
// You can handle the request according to your API requirements.

return {
data,
};
};
custom: async ({
url,
method,
filters,
sorters,
payload,
query,
headers,
meta,
}) => {
// You can handle the request according to your API requirements.

return {
data,
};
};
You can define multiple custom requests inside this method based on the url or method parameters. For more information, you can refer to the Refine documentation on custom methods (https://refine.dev/docs/data/data-provider#custom) and the useCustom hook (https://refine.dev/docs/data/hooks/use-custom). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1029709108686880798> kapa.ai is still learning and improving, please let us know how it did by reacting below