react<T> method

Reactive<T> react<T>(
  1. T initial, [
  2. bool strict = true
])

Creates a Reactive variable and binds it automatically to this state.

This allows the reactive value to trigger setState automatically whenever it changes.

Example:

late final counter = react(0);

ElevatedButton(
  onPressed: () => counter.value++,
  child: Text('${counter.value}'),
);

Implementation

Reactive<T> react<T>(T initial, [bool strict = true]) {
  final r = Reactive<T>(initial, strict);
  r.bind(this);
  return r;
}