The following is sometimes done without updating the data

/ / to monitor the change of the picker UNSAFE_componentWillReceiveProps (nextProps) {if (this. State. LastIllnessTitle! == nextProps.title) { this.setState({ illnessTitle: nextProps.title, }); this.requestData(nextProps.title); }}Copy the code

The React documentation describes setState

void setState(
    function|object nextState,
    [function callback]
)
Copy the code

The second argument is a callback function that is executed when the asynchronous operation of setState ends and the component has been re-rendered. We can use this callback to get the updated state value.

Here's how:

this.setState( { illnessTitle: nextProps.title, }, () => { this.requestData(); });Copy the code