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

# Function: useReducer()

## Call Signature

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

`useState` 的一种替代方案。

当你有涉及多个子值的复杂 state 逻辑时，通常
`useReducer` 比 `useState` 更合适。它还能让你为触发深层
更新的组件优化性能，因为你可以向下传递 `dispatch`，而不是传递回调函数。

### 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`>]

`useState` 的一种替代方案。

当你有涉及多个子值的复杂 state 逻辑时，通常
`useReducer` 比 `useState` 更合适。它还能让你为触发深层
更新的组件优化性能，因为你可以向下传递 `dispatch`，而不是传递回调函数。

### 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)
