@@ -310,8 +310,15 @@ export interface MutationState<TData> {
310310 */
311311export interface MutationOptions {
312312 /**
313- * If true, errors will be rethrown instead of being caught and stored in state.
314- * This allows callers to use try/catch for error handling.
313+ * Controls error handling behavior for the mutation.
314+ *
315+ * - **`false` (default)**: Errors are caught and stored in the `error` state.
316+ * The `mutate` function returns `undefined` on error.
317+ * Use the `isError` flag and `error` state to handle failures reactively.
318+ *
319+ * - **`true`**: Errors are rethrown, allowing try/catch error handling.
320+ * The `mutate` function throws on error.
321+ * Use this when you need imperative error handling.
315322 *
316323 * @default false
317324 */
@@ -322,19 +329,70 @@ export interface MutationOptions {
322329 * Return value of mutation hooks.
323330 *
324331 * @remarks
325- * Combines mutation state with a `mutate` trigger function accepting a payload, along with convenient booleans for status.
332+ * Combines mutation state with a `mutate` trigger function accepting a payload,
333+ * along with convenient booleans for status checking.
334+ *
335+ * ## Return Value Semantics
336+ *
337+ * The `mutate` function returns `Promise<TData | undefined>`:
338+ *
339+ * - **On success**: Returns the mutation result data (`TData`)
340+ * - **On error with `throwOnError: false` (default)**: Returns `undefined` and stores error in `error` state
341+ * - **On error with `throwOnError: true`**: Throws the error (use try/catch)
342+ *
343+ * ## Recommended Patterns
344+ *
345+ * ```ts
346+ * // Pattern 1: Check return value (when throwOnError is false)
347+ * const result = await mutate(payload);
348+ * if (result === undefined) {
349+ * // Check error state
350+ * console.error('Mutation failed:', error);
351+ * } else {
352+ * // Use result
353+ * console.log('Created:', result);
354+ * }
355+ *
356+ * // Pattern 2: Use try/catch (when throwOnError is true)
357+ * try {
358+ * const result = await mutate(payload);
359+ * console.log('Created:', result);
360+ * } catch (err) {
361+ * console.error('Mutation failed:', err);
362+ * }
363+ *
364+ * // Pattern 3: Use status flags (reactive)
365+ * if (isSuccess) {
366+ * console.log('Created:', data);
367+ * }
368+ * if (isError) {
369+ * console.error('Failed:', error);
370+ * }
371+ * ```
326372 *
327373 * @typeParam TData - The type of data returned by the mutation.
328374 * @typeParam TPayload - The payload type accepted by the mutation trigger.
329375 *
330376 * @public
331377 */
332378export interface MutationResult < TData , TPayload > {
379+ /**
380+ * Trigger the mutation with the given payload.
381+ *
382+ * @returns Promise resolving to the mutation result, or `undefined` if an error occurred
383+ * and `throwOnError` is false. When `throwOnError` is true, errors are thrown instead.
384+ */
333385 mutate : ( payload : TPayload ) => Promise < TData | undefined >
386+ /** Current mutation status: 'idle' | 'loading' | 'success' | 'error' */
334387 status : 'idle' | 'loading' | 'success' | 'error'
388+ /** The result data from a successful mutation, or `null` if not yet successful. */
335389 data : TData | null
390+ /** The error from a failed mutation, or `null` if no error. */
336391 error : Error | null
392+ /** `true` while the mutation is in progress. */
337393 isLoading : boolean
394+ /** `true` after a successful mutation. */
338395 isSuccess : boolean
396+ /** `true` after a failed mutation. */
339397 isError : boolean
340398}
0 commit comments