useState<T> function

StateHook<T> useState<T>(
  1. T initialValue
)

Adds local state to a uiFunction component by returning a StateHook with StateHook.value initialized to initialValue.

Note: If the initialValue is expensive to compute, useStateLazy should be used instead.

Example:

UiFactory<UseStateExampleProps> UseStateExample = uiFunction(
  (props) {
    final count = useState(0);
    return Fragment()(
      count.value,
      (Dom.button()..onClick = (_) => count.set(0))('Reset'),
      (Dom.button()
        ..onClick = (_) => count.setWithUpdater((prev) => prev + 1)
      )('+'),
    );
  },
  _$UseStateExampleConfig, // ignore: undefined_identifier
);

Learn more: reactjs.org/docs/hooks-state.html.

Implementation

StateHook<T> useState<T>(T initialValue) => react_hooks.useState<T>(initialValue);