useCreateMany is a modified version of TanStack Query’s useMutation for multiple create mutations.
It uses the createMany method from the dataProvider. If the dataProvider doesn’t have a createMany method, it will call create for each item individually.
Usage
Parameters
You can pass parameters either to the hook or to themutate/mutateAsync functions. Parameters passed to the mutation functions override those passed to the hook.
Resource name for API data interactions.
Array of values for the mutation function - the data to create.
Meta data 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'.successNotification
OpenNotificationParams | false | ((data, values) => OpenNotificationParams | false)
Success notification configuration. Set to
false to disable.errorNotification
OpenNotificationParams | false | ((error, values) => OpenNotificationParams | false)
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
With Async/Await
Pre-configured Hook
With Callbacks
Custom Invalidation
Disable Notifications
With Meta Data
Bulk Import
Type Parameters
TData- Result data type of the mutation. ExtendsBaseRecord.TError- Custom error type that extendsHttpError.TVariables- Type of the values/payload for the mutation.
FAQ
What happens if dataProvider doesn't have createMany?
What happens if dataProvider doesn't have createMany?
If the
dataProvider doesn’t implement the createMany method, Refine will automatically fall back to calling the create method for each item individually.How do I get the created records' IDs?
How do I get the created records' IDs?
Access them from the
data property:Can I prevent automatic query invalidation?
Can I prevent automatic query invalidation?
Yes, set
invalidates to an empty array: