quickest-silver
quickest-silver4mo ago

useForm

in useForm from "@refinedev/antd", how to refetch data when in "edit" and clone mode?
5 Replies
kapa.ai
kapa.ai4mo ago
Hi @Belvis. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In edit and clone modes, Refine uses the useOne hook to fetch data. You can pass the queryOptions options by passing the queryOptions property. This property will only work in the edit and clone actions. Here is an example of how to use it:
useForm({
queryOptions: {
retry: 3,
},
});
useForm({
queryOptions: {
retry: 3,
},
});
In the above example, the retry option is set to 3, which means the query will be retried 3 times in case of failure. You can find more details in the documentation here (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form#queryoptions) and here (https://refine.dev/docs/ui-integrations/mantine/hooks/use-form#queryoptions). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
quickest-silver
quickest-silver4mo ago
@kapa.ai im not saying that refetch when it's fail, refetch when i want
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In Refine, you can manually refetch data using the refetch function provided by the queryResult object from the useForm hook. Here's an example:
const { queryResult: { refetch } } = useForm();
const { queryResult: { refetch } } = useForm();
You can call refetch() whenever you want to manually refetch the data. Additionally, Refine provides a useInvalidate hook that you can use to invalidate certain queries, which will cause them to be refetched. Here's an example:
import { useInvalidate } from "@refinedev/core";

const invalidate = useInvalidate();

// To invalidate the state of a Posts with an id of 1
invalidate({
resource: "posts",
invalidates: ["detail"],
id: 1,
});
import { useInvalidate } from "@refinedev/core";

const invalidate = useInvalidate();

// To invalidate the state of a Posts with an id of 1
invalidate({
resource: "posts",
invalidates: ["detail"],
id: 1,
});
In the above example, the detail query for the posts resource with an id of 1 is invalidated, causing it to be refetched. You can find more details in the documentation here (https://refine.dev/docs/guides-concepts/faq#how-can-i-refetch-data) and here (https://refine.dev/docs/core/hooks/data/use-invalidate/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below