useDeleteMany is a modified version of TanStack Query’s useMutation for multiple delete mutations.
It uses the deleteMany method from the dataProvider. If the dataProvider doesn’t have a deleteMany method, it will call deleteOne for each item individually.
Usage
Parameters
Resource name for API data interactions.
Array of record IDs to delete.
Determines when mutations are executed. See mutation modes.
Duration in ms to wait before executing the mutation when
mutationMode = "undoable".Provides a function to cancel the mutation when
mutationMode = "undoable".Metadata for the dataProvider. Can be used to pass additional parameters to data provider methods.
If there is more than one
dataProvider, you should specify which one to use.Specify which queries should be invalidated after successful mutation. Options:
'list', 'many', 'detail', 'resourceAll', 'all'.Optional values to pass to the delete method (some APIs may require additional data for deletion).
successNotification
OpenNotificationParams | false | ((data, ids) => OpenNotificationParams | false)
Success notification configuration. Set to
false to disable.Error notification configuration. Set to
false to disable.TanStack Query’s
useMutation options.Configuration for loading overtime behavior.
Return Values
Function to trigger the mutation.
Async version that returns a promise.
TanStack Query’s
useMutation return object.Loading overtime information.
Examples
Basic Usage
Bulk Delete with Confirmation
With Optimistic Updates
With Undoable Mode
With Async/Await
With Callbacks
Disable Notifications
With Meta Data
Soft Delete
With Loading State
Type Parameters
TData- Result data type of the mutation. ExtendsBaseRecord.TError- Custom error type that extendsHttpError.TVariables- Type of additional variables/payload for the mutation.
FAQ
What happens if dataProvider doesn't have deleteMany?
What happens if dataProvider doesn't have deleteMany?
If the
dataProvider doesn’t implement the deleteMany method, Refine will automatically fall back to calling the deleteOne method for each ID individually.What are mutation modes?
What are mutation modes?
pessimistic(default): UI updates after server confirmsoptimistic: UI updates immediately, rolls back on errorundoable: UI updates immediately with option to undo before server request
Can I prevent automatic query invalidation?
Can I prevent automatic query invalidation?
Yes, set
invalidates to an empty array:How do I implement soft delete?
How do I implement soft delete?
Pass a
values object with your soft delete fields: