useStateLazy<T> function

StateHook<T> useStateLazy<T>(
  1. T init()
)

Adds local state to a uiFunction component by returning a StateHook with StateHook.value initialized to the return value of init.

Example:

UiFactory<UseStateExampleProps> UseStateExample = uiFunction(
  (props) {
    final count = useStateLazy(() {
      var initialState = someExpensiveComputation(props);
      return initialState;
    });

    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-reference.html#lazy-initial-state.

Implementation

StateHook<T> useStateLazy<T>(T Function() init) => react_hooks.useStateLazy<T>(init);