Skip to content

use_state

Adds state to a function component, similar to React's useState().

The returned setter accepts either
  • a new value, or
  • a function receiving the previous state and returning the next one.

Parameters:

  • initial (StateT | Callable[[], StateT]) –

    Initial state value or a function returning it.

Returns:

  • tuple[StateT, Callable[[StateT | Updater], None]]

    (value, set_value) tuple.