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 the child is different, and the error boundary is currently in an error state,
  // give the children a chance to mount.
  if (state.hasError) {
    final childThatCausedError = typedPropsFactory(prevProps).children!.single;
    if (childThatCausedError != props.children!.single) {
      reset();
    }
  }
}