Skip to content

Mutation

A ChimericMutation represents a write operation. Once instantiated via a React Query or RTK Query factory, usage is identical regardless of the backing library.

Call the mutation as an async function:

// With params
const updatedUser = await updateUser({ id: '123', name: 'New Name' });
// Without params
const result = await clearCache();
// With native library options
const result = await updateUser(
{ id: '123', name: 'New Name' },
{ nativeOptions: { onSuccess: () => console.log('done') } },
);

Use .useHook() inside a React component. Unlike queries, mutations are not auto-executed — you trigger them via invoke.

function EditUserForm({ userId }: { userId: string }) {
const { invoke, isPending, isSuccess, isError, error, data, reset, native } =
updateUser.useHook();
const handleSubmit = async (name: string) => {
await invoke({ id: userId, name });
};
return (
<form onSubmit={(e) => { e.preventDefault(); handleSubmit('New Name'); }}>
<button type="submit" disabled={isPending}>
{isPending ? 'Saving...' : 'Save'}
</button>
{isSuccess && <div>Saved!</div>}
{isError && <div>Error: {error?.message}</div>}
<button type="button" onClick={reset}>Reset</button>
</form>
);
}

Return value:

PropertyTypeDescription
invoke(params, allOptions?) => Promise<TResult>Trigger the mutation
dataTResult | undefinedLast successful result
isPendingbooleanMutation in progress
isIdlebooleanNo mutation attempted
isSuccessbooleanLast mutation succeeded
isErrorbooleanLast mutation errored
errorTError | nullError object
reset() => voidReset state back to idle
nativelibrary-specificFull result from the underlying mutation library