like-gold•16mo ago
When I use useForm and fetch twice call api
When the button is clicked, fetch and useForm each call the API. How to only call fetch?
2 Replies
Hi @florent. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To ensure that only your custom
fetch call is made and not the useForm API call, you need to adjust your useForm configuration. Specifically, you should avoid triggering the onFinish method of useForm since it is responsible for making the API call.
Here's how you can modify your code:
1. Remove the onFinish call: Since you are handling the API call manually, you don't need to call onFinish.
2. Handle form reset and close manually: You can still reset the form and close the modal manually after your custom fetch call.
Here is the updated code:
By removing the onFinish call, you ensure that only your custom fetch call is made when the button is clicked. This prevents the useForm hook from making an additional API call.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1184365192482652173> kapa.ai is still learning and improving, please let us know how it did by reacting below