OnReactive constructor

const OnReactive(
  1. Widget builder(), {
  2. bool shouldRebuild(
    1. SnapState oldSnap,
    2. SnapState newSnap
    )?,
  3. SideEffects? sideEffects,
  4. String? debugPrintWhenRebuild,
  5. String? debugPrintWhenObserverAdd,
  6. Key? key,
})

First choice widget to listen to an injected state.

It explicitly register injected state consumed in its child widget tree.

Example:

final counter1 = RM.inject(()=> 0) // Or just use extension: 0.inj()
final counter2 = 0.inj();
int get sum => counter1.state + counter2.state;

//In the widget tree:
Column(
    children: [
        OnReactive( // Will listen to counter1
            ()=> Text('${counter1.state}');
        ),
        OnReactive( // Will listen to counter2
            ()=> Text('${counter2.state}');
        ),
        OnReactive(// Will listen to both counter1 and counter2
            ()=> Text('$sum');
        )
    ]
)

Implementation

const OnReactive(
  this.builder, {
  this.shouldRebuild,
  this.sideEffects,
  this.debugPrintWhenRebuild,
  this.debugPrintWhenObserverAdd,
  Key? key,
}) : super(key: key);