> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Function: useReducer()

## Call Signature

> **useReducer**\<`S`, `A` _extends_ `AnyActionArg`>(`reducer`: (`prevState`: `S`, ...`args`: `A`) => `S`, `initialState`: `S`): \[`S`, `ActionDispatch`\<`A`>]

An alternative to `useState`.

`useReducer` is usually preferable to `useState` when you have complex state logic that involves
multiple sub-values. It also lets you optimize performance for components that trigger deep
updates because you can pass `dispatch` down instead of callbacks.

### Type Parameters

| Type Parameter               |
| ---------------------------- |
| `S`                          |
| `A` _extends_ `AnyActionArg` |

### Parameters

| Parameter      | Type                                      |
| -------------- | ----------------------------------------- |
| `reducer`      | (`prevState`: `S`, ...`args`: `A`) => `S` |
| `initialState` | `S`                                       |

### Returns

\[`S`, `ActionDispatch`\<`A`>]

### Version

16.8.0

### See

[https://react.dev/reference/react/useReducer](https://react.dev/reference/react/useReducer)

## Call Signature

> **useReducer**\<`S`, `I`, `A` _extends_ `AnyActionArg`>(`reducer`: (`prevState`: `S`, ...`args`: `A`) => `S`, `initialArg`: `I`, `init`: (`i`: `I`) => `S`): \[`S`, `ActionDispatch`\<`A`>]

An alternative to `useState`.

`useReducer` is usually preferable to `useState` when you have complex state logic that involves
multiple sub-values. It also lets you optimize performance for components that trigger deep
updates because you can pass `dispatch` down instead of callbacks.

### Type Parameters

| Type Parameter               |
| ---------------------------- |
| `S`                          |
| `I`                          |
| `A` _extends_ `AnyActionArg` |

### Parameters

| Parameter    | Type                                      |
| ------------ | ----------------------------------------- |
| `reducer`    | (`prevState`: `S`, ...`args`: `A`) => `S` |
| `initialArg` | `I`                                       |
| `init`       | (`i`: `I`) => `S`                         |

### Returns

\[`S`, `ActionDispatch`\<`A`>]

### Version

16.8.0

### See

[https://react.dev/reference/react/useReducer](https://react.dev/reference/react/useReducer)
