Weird edit() behaviour
Hi all,
I'm experiencing a weird behaviour
if I set an EDIT path for a resource, as soon as I go to that path the system is automatically trying to load the resource as [my_api]/resource/ID
both with a GET and OPTION request
but I'm not actually adding any of those in my code... is that an automated behaviour? how can I disable it?
6 Replies
Hi @simoneb. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, this is an automated behavior in refine. When you navigate to an edit path for a resource, refine automatically tries to fetch the data for that resource using the ID from the URL. This is part of refine's convention-based approach to simplify common CRUD operations.
This behavior is implemented in the
useForm
hook, which is typically used in edit pages. The hook automatically makes a GET request to fetch the resource data when it mounts.
According to the Github issue #1260:
When usingIf you want to disable this automatic data fetching, you have a few options: 1. Use theuseForm
oruseModalForm
on resource A in the Show context of resource B - a GET request is being performed to resource A with the ID of shown resource B.
queryOptions
prop of useForm
to disable the automatic query:
2. If you're using the <Edit>
component, you can pass the queryOptions
prop to it:
3. If you need more control over when and how the data is fetched, you might consider using useForm
with manual mode and handling the data fetching yourself.
Remember that disabling this automatic behavior means you'll need to handle data fetching manually if you still need the resource data in your edit form.
For more detailed information about the useForm
hook and its options, you can refer to the refine documentation on useForm.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@539513465103056900> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-blackOP•3w ago
If I try I'm getting an error
Object literal may only specify known properties, and 'queryOptions' does not exist in type 'UseFormProps<BaseRecord, HttpError, FieldValues, {}, BaseRecord, BaseRecord, HttpError>'
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize for the confusion in my previous answer. It seems the error you're encountering is related to the type definition of
UseFormProps
. Let's clarify this based on the current refine documentation.
According to the refine documentation on useForm, the queryOptions
property should be nested under the refineCoreProps
object when using @refinedev/react-hook-form
. Here's the correct way to disable the automatic query:
This structure is confirmed in the documentation for queryOptions:
The error you're seeing suggests that you're trying to pass queryOptions
directly to useForm
, which is not correct for the @refinedev/react-hook-form
package.
If you're using a different package or version, please let me know, and I can provide more specific guidance.
Remember, this approach will only work in edit
or clone
mode, as mentioned in the documentation:
Works only inIf you're still encountering issues after making this change, please provide more details about your setup, including the exact version of refine and the package you're using for forms. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------action: "edit"
oraction: "clone"
mode.
<@539513465103056900> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-blackOP•3w ago
great, it is actually working, thanks