For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/react/Hooks/useReducer.md.
  • English
  • 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

    ParameterType
    reducer(prevState: S, ...args: A) => S
    initialStateS

    Returns

    [S, ActionDispatch<A>]

    Version

    16.8.0

    See

    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

    ParameterType
    reducer(prevState: S, ...args: A) => S
    initialArgI
    init(i: I) => S

    Returns

    [S, ActionDispatch<A>]

    Version

    16.8.0

    See

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

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.