lazyState<T> method

(T, void Function(T)) lazyState<T>(
  1. T init()
)

Side effect that provides a way for capsules to contain some state, where the initial state is computationally expensive.

Similar to the useState hook from React; see https://react.dev/reference/react/useState

NOTE

While lazyState will continue to work just fine, it is recommended that newer applications also take a look at lazyData.

Implementation

(T, void Function(T)) lazyState<T>(T Function() init) {
  final (getter, setter) = use.lazyData(init);
  return (getter(), setter);
}