setStateWithUpdater method

  1. @override
void setStateWithUpdater(
  1. Component2 component,
  2. StateUpdaterCallback stateUpdater,
  3. SetStateCallback? callback
)
override

Implementation

@override
void setStateWithUpdater(Component2 component, StateUpdaterCallback stateUpdater, SetStateCallback? callback) {
  final firstArg = allowInterop((JsMap jsPrevState, JsMap jsProps, [_]) {
    final value = stateUpdater(
      JsBackedMap.backedBy(jsPrevState),
      JsBackedMap.backedBy(jsProps),
    );
    if (value == null) return null;
    return jsBackingMapOrJsCopy(value);
  });

  if (callback == null) {
    component.jsThis.setState(firstArg);
  } else {
    component.jsThis.setState(firstArg, allowInterop(([_]) {
      callback();
    }));
  }
}