Can't I use edit without entering id in useForm?
[useForm]: action: "edit", resource: "firstevent", id: undefined
If you don't use the
setId
method to set the id
, you should pass the id
prop to useForm
. Otherwise, useForm
will not be able to infer the id
from the current URL.
___
const firstEventResponse = await fetch(http://localhost:4000/firstevent
);
const firstEvent = await firstEventResponse.json();
"first event": { "id": 1, "event term": 1111, "event check": "N" },
We are receiving this type of data.
I don't want it to be http://localhost:4000/firstevent/1.
How to save data without using id?2 Replies
Hi @florent_26629. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In the
useForm
hook of Refine, the id
is required when the action
is set to "edit"
or "clone"
. By default, useForm
infers the id
from the URL. If the URL doesn't contain the id
params, you must provide it manually. This is because the id
is used to determine the record to edit or clone.
Here is an example of how you can define the id
in the useForm
options:
You can also use the setId
method to set the id
after the form is mounted:
If you want to save data without using an id
, you might want to consider using the "create"
action instead of "edit"
. The "create"
action is used to create a new record, and it doesn't require an id
.
Here is an example:
Please note that this will create a new record instead of editing an existing one.
For more information, you can refer to the official documentation of Refine here (https://refine.dev/docs/packages/react-hook-form/use-form#id) and here (https://refine.dev/docs/guides-concepts/routing#useform-).
----------------------
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