# useTanstackQueryMutationPropertyOrder

Rule `biome/useTanstackQueryMutationPropertyOrder`. Enforce that `onMutate` comes before `onError` and `onSettled` in the options of TanStack Query mutations.

- Source: biome
- Technologies: React
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 30.6M weekly downloads of presets that enable it
- Trend: +109.3% last quarter
- Rank: #616 by reach, #251 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Biome | `nursery/useTanstackQueryMutationPropertyOrder` | yes | unsafe | group nursery, since 2.6.9 | [docs](https://biomejs.dev/linter/rules/use-tanstack-query-mutation-property-order/) |

## Code examples

### Incorrect: the rule reports this

```js
import { useMutation } from "@tanstack/react-query";

useMutation({
    mutationFn: (todo) => saveTodo(todo),
    onError: (error, todo, saved) => restoreTodo(saved.previousTodo),
    onMutate: (todo) => ({ previousTodo: readTodo(todo.id) }),
});
```

```js
import { useMutation } from "@tanstack/react-query";

useMutation({
    onSettled: (data, error, todo, saved) => refreshTodo(saved.previousTodo),
    mutationFn: (todo) => saveTodo(todo),
    onMutate: (todo) => ({ previousTodo: readTodo(todo.id) }),
});
```

### Correct: the rule accepts this

```js
import { useMutation } from "@tanstack/react-query";

useMutation({
    mutationFn: (todo) => saveTodo(todo),
    onMutate: (todo) => ({ previousTodo: readTodo(todo.id) }),
    onError: (error, todo, saved) => restoreTodo(saved.previousTodo),
    onSettled: (data, error, todo, saved) => refreshTodo(saved.previousTodo),
});

useMutation({
    onMutate: (todo) => ({ previousTodo: readTodo(todo.id) }),
    onSettled: (data, error, todo, saved) => refreshTodo(saved.previousTodo),
    onError: (error, todo, saved) => restoreTodo(saved.previousTodo),
    mutationFn: (todo) => saveTodo(todo),
});
```

Examples from the Biome documentation.

## Enable it

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useTanstackQueryMutationPropertyOrder": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |

## Related rules

- [biome/useTanstackQueryInfiniteQueryPropertyOrder](https://lintradar.dev/rules/biome/useTanstackQueryInfiniteQueryPropertyOrder.md): Enforce a consistent property order in the options of TanStack Query infinite query functions.
- [biome/useTanstackQueryQueryOptions](https://lintradar.dev/rules/biome/useTanstackQueryQueryOptions.md): Require TanStack Query options to be created with `queryOptions()`.
- [biome/useTanstackQueryExhaustiveDependencies](https://lintradar.dev/rules/biome/useTanstackQueryExhaustiveDependencies.md): Require query keys to include every value that the query function uses.
- [biome/useTanstackQueryStableQueryClient](https://lintradar.dev/rules/biome/useTanstackQueryStableQueryClient.md): Require the TanStack Query `QueryClient` to be created once, not on every render.
- [biome/useTailwindVariablesShorthand](https://lintradar.dev/rules/biome/useTailwindVariablesShorthand.md): Enforce the shorthand syntax for CSS variables in Tailwind CSS classes.
- [biome/noImportantStyles](https://lintradar.dev/rules/biome/noImportantStyles.md): Disallow `!important` declarations.

---

Web page: https://lintradar.dev/rules/biome/useTanstackQueryMutationPropertyOrder. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
