setState method

void setState(
  1. covariant dynamic newState, [
  2. dynamic callback()?
])
inherited

Triggers a rerender with new state obtained by shallow-merging newState into the current state.

Optionally accepts a callback that gets called after the component updates.

Also allows newState to be used as a transactional setState callback.

See: reactjs.org/docs/react-component.html#setstate

Implementation

void setState(covariant dynamic newState, [Function()? callback]) {
  if (newState is Map) {
    _nextState!.addAll(newState);
  } else if (newState is StateUpdaterCallback) {
    _transactionalSetStateCallbacks.add(newState);
  } else if (newState != null) {
    throw ArgumentError(
        'setState expects its first parameter to either be a Map or a `TransactionalSetStateCallback`.');
  }

  if (callback != null) _setStateCallbacks.add(callback);

  _jsRedraw();
}