Skip to content

use_state

API

counterweight.hooks.use_state

use_state(
    initial_value: Getter[T] | T,
) -> tuple[T, Setter[T]]
PARAMETER DESCRIPTION
initial_value

The initial value of the state. It can either be the initial value itself, or a zero-argument function that returns the initial value.

TYPE: Getter[T] | T

RETURNS DESCRIPTION
T

The current value of the state (i.e., for the current render cycle).

Setter[T]

A function that can be called to update the value of the state (e.g., in an event handler). It can either be called with the new value of the state, or a function that takes the current value of the state and returns the new value of the state. If the value is not equal to the current of the state, Counterweight will trigger a render cycle.

counterweight.hooks.Getter module-attribute

Getter = Callable[[], T]

counterweight.hooks.Setter module-attribute

Setter = Callable[[Callable[[T], T] | T], None]