Skip to main content

Interface: ReactMutation<API, Name>

react.ReactMutation

Type parameters

NameType
APIextends GenericAPI
Nameextends MutationNames<API>

Callable

ReactMutation

ReactMutation(...args): Promise<ReturnType<NamedMutation<API, Name>>>

Execute the mutation on the server, returning a Promise of its return value.

Parameters

NameTypeDescription
...argsParameters<NamedMutation<API, Name>>Arguments for the mutation to pass up to the server.

Returns

Promise<ReturnType<NamedMutation<API, Name>>>

The return value of the server-side function call.

Methods

withOptimisticUpdate

withOptimisticUpdate(optimisticUpdate): ReactMutation<API, Name>

Define an optimistic update to apply as part of this mutation.

This is a temporary update to the local query results to facilitate a fast, interactive UI. It enables query results to update before a mutation executed on the server.

When the mutation is invoked, the optimistic update will be applied.

Optimistic updates can also be used to temporarily remove queries from the client and create loading experiences until a mutation completes and the new query results are synced.

The update will be automatically rolled back when the mutation is fully completed and queries have been updated.

Parameters

NameTypeDescription
optimisticUpdateOptimisticUpdate<API, Parameters<NamedMutation<API, Name>>>The optimistic update to apply.

Returns

ReactMutation<API, Name>

A new ReactMutation with the update configured.