Skip to main content

useOvokMutation

Wraps a typed OvokClient operation as an explicit stateful mutation.

When to use it​

The callback receives the provider client and typed payload; mutate runs it, normalizes and rethrows errors, and reset clears state.

Setup​

Call it from a client-side React component below OvokProvider so it uses the client configured at that provider boundary.

Hook arguments​

ArgumentTypeDetails
mutateRequest(client: OvokClient, params: TParams) => Promise<TData>Callback that receives the configured client and typed input and returns a promise.

TypeScript signature​

<TParams, TData>(mutateRequest: (client: OvokClient, params: TParams) => Promise<TData>): OvokMutationState<TParams, TData>

Mutation state​

The operation runs only when you call mutate(payload). The payload type is TParams; the returned promise and data carry TData.

FieldMeaning
dataLatest successful result, or undefined before success.
loadingWhether the mutation is running.
errorNormalized Error from the latest failure.
mutateStarts the operation, resolves with its result, and rejects on failure.
resetClears mutation data and error state.

Request behavior​

The mutation is explicit: collect and validate the input in your UI, disable repeated submission while loading is true, handle the rejected promise, and render error near the action.

Example​

Call the mutation from an event handler and show its error beside the action.

import { useOvokMutation } from '@ovok/core';

export function ConsentAction({ accepted }: { accepted: boolean }) {
const { mutate, loading, error } = useOvokMutation((client, value: boolean) => client.setLegalConsent(value));
async function save() {
try { await mutate(accepted); } catch { /* The hook exposes the error below. */ }
}
return <><button disabled={loading} onClick={() => void save()}>Save consent</button>
{error && <p role="alert">{error.message}</p>}</>;
}