> ## Documentation Index
> Fetch the complete documentation index at: https://docs.modelence.com/llms.txt
> Use this file to discover all available pages before exploring further.

# modelenceMutation

[API Reference](/api-reference/@modelence/react-query/functions/../../../index) / [@modelence/react-query](/api-reference/@modelence/react-query/functions/../index) / modelenceMutation

> **modelenceMutation**\<`T`>(`methodName`, `defaultArgs`): `object`

Defined in: [index.ts:242](https://github.com/modelence/modelence/blob/f614ecc6811cdda9670d612872c8ff49a49c5e28/packages/react-query/src/index.ts#L242)

Creates mutation options for use with TanStack Query's useMutation hook.

## Example

```tsx theme={null}
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { modelenceMutation } from '@modelence/react-query';

function MyComponent() {
  const queryClient = useQueryClient();
  
  // Basic usage
  const { mutate } = useMutation(modelenceMutation('todos.create'));

  // With additional options
  const { mutate: updateTodo } = useMutation({
    ...modelenceMutation('todos.update'),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['todos.getAll'] });
    },
  });

  return <button onClick={() => mutate({ title: 'New Todo' })}>Create</button>;
}
```

## Type Parameters

| Type Parameter | Default type | Description                              |
| -------------- | ------------ | ---------------------------------------- |
| `T`            | `unknown`    | The expected return type of the mutation |

## Parameters

| Parameter     | Type     | Description                                                 |
| ------------- | -------- | ----------------------------------------------------------- |
| `methodName`  | `string` | The name of the method to mutate                            |
| `defaultArgs` | `Args`   | Optional default arguments to merge with mutation variables |

## Returns

`object`

Mutation options object for TanStack Query's useMutation

| Name           | Type                             | Defined in                                                                                                                                  |
| -------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `mutationFn()` | (`variables`) => `Promise`\<`T`> | [index.ts:247](https://github.com/modelence/modelence/blob/f614ecc6811cdda9670d612872c8ff49a49c5e28/packages/react-query/src/index.ts#L247) |
