cloning
I need to add the cloning action, but it seems that I need to duplicate the edit page for that? kinda counter productive to have to duplicate code
3 Replies
Hi @SetiZ. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To add cloning functionality in your refine application, you don't necessarily need to duplicate the entire edit page. Instead, you can leverage the
action: "clone"
property provided by refine's hooks. This property allows you to clone an existing record by fetching its data and creating a new record with it.
Here are the steps to add cloning functionality using refine's useModalForm
hook with Ant Design:
1. Add the Clone Button to Your List:
You need to add a <CloneButton />
to each record in your list. This button will open a modal form for cloning the record.
2. Ensure Proper Routing:
Make sure that your routes include the clone action. If you are using resource routing, you need to specify the clone page in your resources.
3. Handle the Clone Action:
The useModalForm
hook with action: "clone"
will handle fetching the record data and creating a new record upon form submission.
By following these steps, you can add cloning functionality without duplicating the entire edit page. The useModalForm
hook with the action: "clone"
property simplifies the process by handling the data fetching and form submission for you.
For more detailed information, you can refer to the useModalForm documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-modal-form/#usage).
If you encounter any issues, make sure to check if your routes are correctly set up and that the clone action is properly defined in your resources.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@267689263246606336> kapa.ai is still learning and improving, please let us know how it did by reacting below
reduced-jade•2mo ago
sorry that doesn't answer my question.