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, and this page is available as Markdown at /next/zh/api/react/Hooks/useReducer.md.
  • 简体中文
  • 函数: useReducer()

    调用签名

    useReducer<S, A extends AnyActionArg>(reducer: (prevState: S, ...args: A) => S, initialState: S): [S, ActionDispatch<A>]

    useState 的一种替代方案。

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

    类型参数

    类型参数
    S
    A extends AnyActionArg

    参数

    参数类型
    reducer(prevState: S, ...args: A) => S
    initialStateS

    返回

    [S, ActionDispatch<A>]

    Version

    16.8.0

    参阅

    https://react.dev/reference/react/useReducer

    调用签名

    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,而不是传递回调函数。

    类型参数

    类型参数
    S
    I
    A extends AnyActionArg

    参数

    参数类型
    reducer(prevState: S, ...args: A) => S
    initialArgI
    init(i: I) => S

    返回

    [S, ActionDispatch<A>]

    Version

    16.8.0

    参阅

    https://react.dev/reference/react/useReducer

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。