Custom hook that creates a mutable reference to a state value and a function to update the state value.

  • Type Parameters

    • S = undefined

      The type of the state value

    Parameters

    • OptionalinitialState: S | () => S

      The initial state value or a function that returns the initial state value

    Returns readonly [any, (dispatch: S | (prevState: S) => S) => void]

    • An array containing the state reference and handleState function