useUpdateMany to update different ids with different data for each id
useUpdateMany({resource:'', ids:IdArray, values: what to give here ?})
id1 has different value than id2 and so on..
8 Replies
Hi @shubham.srv. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
useUpdateMany
is designed to update multiple records with the same values. If you want to update each record with different values, you should use the useUpdate
hook instead. You can loop through the records and call the mutate
function for each record with its specific values.
Here's an example of how you can use useUpdate
to update multiple records with different values:
Keep in mind that this will make separate requests for each update. If you need to update multiple records with different values in a single request, you may need to implement a custom data provider method to handle this specific use case.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@1003590847960449024> kapa.ai is still learning and improving, please let us how it did by reacting below
ratty-blush•2y ago
@kapa.ai I want to update all data in one api call.
Let me check the knowledge base for you. One moment! :books:
----------------------
In that case, you'll need to implement a custom data provider method to handle updating multiple records with different values in a single API call. Here's an example of how you can create a custom method in your data provider:
Then, you can create a custom hook to use this
updateMultiple
method:
Now, you can use the useUpdateMultiple
hook in your component to update multiple records with different values in a single API call:
Please note that this is a custom implementation, and you'll need to adjust it according to your API requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@1003590847960449024> kapa.ai is still learning and improving, please let us how it did by reacting below
conscious-sapphire•2y ago
Hey @shubham.srv,
useUpdateMany
is designed to update the given ids
with values
. You can make your own implementation using meta
.ratty-blush•2y ago
@salihozdemir hi. Could you please give me a sample format ?
conscious-sapphire•2y ago
You can find more information here: https://refine.dev/docs/tutorial/understanding-dataprovider/create-dataprovider/#meta-usage