You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to RTK query and I meet up a need to call multiple APIs to delete a batch of resources.
// Need to delete all corresponding resources separatelyconst[deleteName,deleteNameResponse]=useDeleteNameMutation();const[deleteSubject,deleteSubjectResponse]=useDeleteSubjectMutation();// Currently, a array is got to delete {names: ["Alice", "Bob"], subjects: ["Math", "Geography", "Physics"]}consthandleDelete=()=>{try{for(constNameofnames){awaitdeleteName({name: Name}).unwrap();}}catch(e){returnPromise.reject(deleteNameResponse)}}try{for(constSubjectofsubjects){awaitdeleteSubject({subject: Subject}).unwrap();}}catch(e){returnPromise.reject(deleteSubjectResponse)}}
Out of handleDelete the Promise will be handled for more actions like
At present, I find that when some error occur, the returned Response nested in returned Promise may not bear the desired info. But seems like a new unfired query/mutation.
But when I call the action for the second time, it seems I can get desired result.
Any idea about that? Also, is it a good way to batch the mutation with error handling and generated codes? If not, is there any best practice about this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I am new to RTK query and I meet up a need to call multiple APIs to delete a batch of resources.
Out of
handleDelete
thePromise
will be handled for more actions likeAt present, I find that when some error occur, the returned

Response
nested in returnedPromise
may not bear the desired info. But seems like a new unfired query/mutation.But when I call the action for the second time, it seems I can get desired result.

Any idea about that? Also, is it a good way to batch the mutation with error handling and generated codes? If not, is there any best practice about this?
Appreciated.
Beta Was this translation helpful? Give feedback.
All reactions