Reusable Form component for #edit and #create
I know I've seen a question about a reusable Form component that can both be used for #edit and #create. As we're starting to build more complex workflows, I'd love to have reusable Fields-Component that I can use in another Context (like a DTO) to avoid duplication. @kapa.ai is that possible? We're using AntD as the Component-Framework.
2 Replies
Hi @bastianwegge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible to create reusable Form components in Refine using Ant Design. You can use the
useForm
hook provided by Refine to manage form data and handle actions like create and edit. This hook offers adapters that let Refine integrate with Ant Design's <Form>
component.
Here's an example of how you can use the useForm
hook to create a form:
In this example, useForm
is used to handle form data. The formProps
includes all necessary values to manage Ant Design Form components. The saveButtonProps
is used to handle the form submission.
You can also use the useForm
hook to create an editing form:
In this example, if you navigate to /posts/edit/1234
it will manage the data of the post with id of 1234
in an editing context.
You can find more detailed information in the Refine Documentation (https://refine.dev/docs/api-reference/antd/hooks/form/useForm) and Refine Blog (https://refine.dev/blog/react-crud-app-with-dynamic-form-ant-design).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below