abundant-blush•8mo ago
useForm refetch
how to refetch with useForm ?
5 Replies
Hi @koop_g. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To refetch data with
useForm in refine, you can use the refetch function provided by the queryResult object. Here's how you can do it:
The refetch function is part of the queryResult object returned by useForm. This approach works for the edit and clone actions of useForm, as these modes use the useOne hook to fetch data.
Alternatively, you can also use the useInvalidate hook to invalidate the form data, which will trigger a refetch:
These methods are documented in the Refine FAQ under the "How can I refetch data?" section.
Remember that refine automatically invalidates affected resources after mutations, so manual refetching is often unnecessary unless you have specific requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1327562833537400895> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
abundant-blushOP•8mo ago
@kapa.ai can you modify my current call so I can understand better ?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on your current code, I can help you modify it to include the
refetch functionality. Here's how you can modify your useForm call to access and use the refetch function:
In this modified version:
1. We keep your existing useForm configuration intact.
2. We extract the refetch function from the queryResult object, which is part of the refineCore property returned by useForm.
3. We create a handleRefetch function that you can call whenever you need to refetch the form data.
You can now use handleRefetch() in your component to trigger a refetch of the form data. For example, you might call it in response to a button click or some other event:
This approach allows you to manually refetch the form data when needed, while keeping your existing form configuration and behavior.
Remember that in the edit mode, useForm uses the useOne hook internally to fetch data, so the refetch function will re-run this query to get the latest data for your form.
Refine useForm Documentation
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1327562833537400895> Kapa.ai is still learning and improving, please let me know how I did by reacting below.