like-gold•17h ago
useUpdate by documentId
Is it possible to use useUpdate with documentId instead of id?
2 Replies
Hi @bogdand2011. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, the useUpdate hook in refine requires an id parameter to identify which record to update. By default, this id is passed to the dataProvider's update method as the identifier for the record to be updated. There is no built-in option to directly use a different field, such as documentId, in place of id in the standard useUpdate API.
However, for some data providers (like Supabase or PostgREST), there have been discussions and feature requests to allow overriding the id selector via the meta or metaData property. For example, you can pass metaData: { id: "documentId" } to some hooks, and the data provider may use documentId as the key instead of id, but this is not a universal feature and depends on the specific data provider's implementation and support for this pattern. This approach is not documented as a general feature for all data providers in refine, and its support may vary or require custom implementation in your data provider logic. For most cases, refine expects a single id field as the identifier for updates, and you may need to customize your data provider to support alternative keys like documentId if needed Supabase: Allow overriding the "id" selector via metaData.
In summary: Out of the box, useUpdate expects an id field. Using documentId instead would require custom handling in your data provider, or leveraging meta/metaData if your data provider supports it. The knowledge sources do not describe a universal, built-in way to use documentId directly with useUpdate.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1050096218518339645> Kapa.ai is still learning and improving, please let me know how I did by reacting below.