national-gold•3mo ago
useupdate without id
I want to incorporate the id in the resource path, or append an extra part of the url when using useupdate, how can I do that
5 Replies
Hi @Todilo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Refine's useUpdate hook expects the id to be provided as a separate parameter, not embedded within the resource path. When you call mutate, the id is passed to the dataProvider's update method as a separate argument, and the resource parameter is typically just the base path (e.g., "products"), not a path with :id or a custom segment.
If you want to customize the URL structure (for example, to append an extra part or incorporate the id directly into the path), you need to handle this logic inside your custom dataProvider. The mutate call itself does not interpolate the id into the resource string; it simply passes both resource and id to the dataProvider, and it's up to your dataProvider to construct the final URL.
For example, you might call:
And in your dataProvider's update method, you would construct the URL as needed:
If you try to pass a resource like "/products/:id/customize" and an id, Refine will not interpolate :id for you; it will treat the resource string literally and append the id at the end, which is likely not what you want. The recommended approach is to keep resource and id separate and handle any custom URL logic in your dataProvider's implementation. This is also confirmed by user discussions and issues, where the workaround is to interpolate the string yourself and pass an empty id, but this is not the standard or recommended pattern in Refine as of now see related discussion.
In summary:
- Pass resource and id separately to useUpdate/mutate. - Handle any custom URL construction in your dataProvider's update method. - Refine does not natively interpolate id into resource paths. If you need to pass additional information, you can use the meta property to send custom data to your dataProvider, but this does not affect URL construction directly see meta usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
- Pass resource and id separately to useUpdate/mutate. - Handle any custom URL construction in your dataProvider's update method. - Refine does not natively interpolate id into resource paths. If you need to pass additional information, you can use the meta property to send custom data to your dataProvider, but this does not affect URL construction directly see meta usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@207945811592478720> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
national-goldOP•3mo ago
@kapa.ai if I have a resource with /articles/:modelId/create
If I add meta: { modelId: mymodelid } , the url gets updated correctly but how do I retrieve that part of the url
/articles/mymodelid/create
Let me check the knowledge base for you again. One moment! :books:
----------------------
When you define a resource path like /articles/:modelId/create in Refine and use meta: { modelId: mymodelid } when navigating (e.g., with a button or navigation method), Refine will automatically interpolate the :modelId segment in the URL with the value from meta. This means the navigation will correctly go to /articles/mymodelid/create.
To retrieve the modelId part from the URL in your page or component, you should use Refine's useParsed hook, which parses the current route parameters. For example:
This will give you access to the modelId from the URL, so you can use it in your component logic.
This pattern is confirmed in the official discussion, where it's explained that meta is used to populate the route segment, and once present in the URL, Refine will infer it from the URL and make it available for your use How do I configure the provider and resources to use /:comicId/chapters/:id?.
In summary:
- Use meta: { modelId: mymodelid } to populate the URL segment.
- Use useParsed to retrieve modelId from the URL in your component.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@207945811592478720> Kapa.ai is still learning and improving, please let me know how I did by reacting below.