Skip to content

API Documentation / @pinia/colada / UseMutationOptionsGlobal

Interface: UseMutationOptionsGlobal ​

Options for mutations that can be globally overridden.

Properties ​

delay? ​

ts
optional delay?: number | false;

Delay in milliseconds to wait before letting the asyncStatus become 'loading'. Set to false or 0 to disable. Requires the PiniaColadaDelay or PiniaColadaDelayMutations plugin.

Default ​

ts
200

gcTime? ​

ts
optional gcTime?: number | false;

Time in ms after which, once the mutation is no longer being used, it will be garbage collected to free resources. Set to false to disable garbage collection (not recommended).

Default ​

ts
60_000 (1 minute)

onError? ​

ts
optional onError?: (error, vars, context) => unknown;

Runs when a mutation encounters an error.

Parameters ​

error ​

unknown

The error thrown by the mutation.

vars ​

unknown

The variables passed to the mutation.

context ​

UseMutationContextCommon<unknown, unknown, unknown, _EmptyObject> & UseMutationGlobalContext | Partial<Record<never, never>>

The merged context from onMutate and the global context. Properties returned by onMutate can be undefined if onMutate throws.

Returns ​

unknown


onMutate? ​

ts
optional onMutate?: (vars, context) => _Awaitable<void | UseMutationGlobalContext | null | undefined>;

Runs before a mutation is executed. It can return a value that will be passed to mutation, onSuccess, onError and onSettled. If it returns a promise, it will be awaited before running mutation.

Parameters ​

vars ​

unknown

The variables passed to the mutation.

context ​

UseMutationContextCommon

The context seeded by the runtime, containing the mutation entry.

Returns ​

_Awaitable<void | UseMutationGlobalContext | null | undefined>


onSettled? ​

ts
optional onSettled?: (data, error, vars, context) => unknown;

Runs after the mutation is settled, regardless of the result.

Parameters ​

data ​

unknown

The result of the mutation. undefined when a mutation failed.

error ​

unknown

The error thrown by the mutation. undefined if the mutation was successful.

vars ​

unknown

The variables passed to the mutation.

context ​

UseMutationContextCommon<unknown, unknown, unknown, _EmptyObject> & UseMutationGlobalContext | Partial<Record<never, never>>

The merged context from onMutate and the global context. Properties returned by onMutate can be undefined if onMutate throws.

Returns ​

unknown


onSuccess? ​

ts
optional onSuccess?: (data, vars, context) => unknown;

Runs when a mutation is successful.

Parameters ​

data ​

unknown

The result of the mutation.

vars ​

unknown

The variables passed to the mutation.

context ​

UseMutationContextCommon<unknown, unknown, unknown, _EmptyObject> & UseMutationGlobalContext

The merged context from onMutate and the global context.

Returns ​

unknown

Released under the MIT License.