componentWillUpdate method

  1. @override
  2. @mustCallSuper
  3. @Deprecated('Only supported in the deprecated Component, and not in Component2. See doc comment for more info.')
void componentWillUpdate(
  1. Map nextProps,
  2. Map nextState
)
override

ReactJS lifecycle method that is invoked when a Component is receiving new props (nextProps) and/or state (nextState).

DEPRECATED - DO NOT USE

This will be removed along with Component in a future major release

Use getSnapshotBeforeUpdate instead as shown in the example below.

// Before
@override
componentWillUpdate(Map nextProps, Map nextState) {
  if (nextProps['someValue'] > props['someValue']) {
    _someInstanceField = deriveNewValueFromNewProps(nextProps['someValue']);
  }

  if (nextState['someStateValue'] != state['someStateValue']) {
    triggerSomeOtherActionOutsideOfThisComponent(nextState['someStateValue']);
  }
}

// After
@override
getSnapshotBeforeUpdate(Map prevProps, Map prevState) {
  // * The reference to `nextProps` from `componentWillUpdate` should be updated to `props` here
  // * The reference to `props` from `componentWillUpdate` should be updated to `prevProps`.
  if (props['someValue'] > prevProps['someValue']) {
    _someInstanceField = deriveNewValueFromNewProps(props['someValue']);
  }

  // * The reference to `nextState` from `componentWillUpdate` should be updated to `state` here
  // * The reference to `state` from `componentWillUpdate` should be updated to `prevState`.
  if (state['someStateValue'] != prevState['someStateValue']) {
    triggerSomeOtherActionOutsideOfThisComponent(state['someStateValue']);
  }

  // NOTE: You could also return a `snapshot` value from this method for later use in `componentDidUpdate`.
}

Implementation

@override
@mustCallSuper
@Deprecated('Only supported in the deprecated Component, and not in Component2. See doc comment for more info.')
void componentWillUpdate(Map nextProps, Map nextState) => throw _unsupportedLifecycleError('componentWillUpdate');