componentDidUpdate method

  1. @override
void componentDidUpdate(
  1. Map prevProps,
  2. Map prevState, [
  3. dynamic snapshot
])
override

ReactJS lifecycle method that is invoked immediately after the Component's updates are flushed to the DOM.

This method is not called for the initial render.

Use this as an opportunity to operate on the root node (DOM) when the Component has been updated as a result of the values of prevProps / prevState.

Note: React 16 added a third parameter to componentDidUpdate, which is a custom value returned from getSnapshotBeforeUpdate. If a value is not returned from getSnapshotBeforeUpdate, the snapshot parameter in componentDidUpdate will be null.

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

Implementation

@override
void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
  if (state.$transitionPhase == typedStateFactory(prevState).$transitionPhase) return;

  if (state.$transitionPhase != TransitionPhase.SHOWING) {
    // Allows the `WithTransitionComponent` to handle state changes that interrupt state
    // changes waiting on `transitionend` events.
    _cancelTransitionEventListener();
  }

  switch (state.$transitionPhase) {
    case TransitionPhase.PRE_SHOWING:
      _handlePreShowing();
      break;
    case TransitionPhase.SHOWING:
      props.onWillShow?.call();
      break;
    case TransitionPhase.HIDING:
      props.onWillHide?.call();
      _handleHiding();
      break;
    case TransitionPhase.HIDDEN:
      props.onDidHide?.call();
      break;
    case TransitionPhase.SHOWN:
      props.onDidShow?.call();
      break;
  }
}