Api request on button press
So I have a resource where the status can be approved or rejected by doing /budget-requests/{id}/approve or ..../reject, what hooks can I use to call this on button press?
2 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:
----------------------
To call an API endpoint on button press for approving or rejecting a budget request in refine, you can use the
useCustomMutation
hook. This hook is designed for sending custom mutation requests and is well-suited for your use case. Here's how you can implement it:
1. First, import the useCustomMutation
hook:
2. Then, inside your component, set up the mutation:
3. Use these functions in your button onClick handlers:
The useCustomMutation
hook allows you to send custom requests to your API endpoints. It's particularly useful for actions that don't fit into the standard CRUD operations useCustomMutation documentation (https://refine.dev/docs/data/hooks/use-custom-mutation/).
If you need to add headers or additional configuration to your request, you can do so using the config
property:
Remember to handle loading states and error cases as needed in your component. The useCustomMutation
hook provides properties like isLoading
and error
that you can use for this purpose useCustomMutation API Reference (https://refine.dev/docs/data/hooks/use-custom-mutation/#api-reference).
----------------------
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 me know how I did by reacting below.