Fix setState within setState

This commit is contained in:
Kimmo Puputti 2018-08-08 13:50:29 +03:00
parent 1cb05da531
commit cfeeca49b4

View file

@ -375,13 +375,21 @@ class LocationAutocompleteInputGoogleMaps extends Component {
}
handlePredictionsSelectEnd(index) {
this.setState(prevState => {
if (!prevState.isSwipe) {
this.selectItem(index);
this.finalizeSelection();
let selectAndFinalize = false;
this.setState(
prevState => {
if (!prevState.isSwipe) {
selectAndFinalize = true;
}
return { selectionInProgress: false, touchStartedFrom: null, isSwipe: false };
},
() => {
if (selectAndFinalize) {
this.selectItem(index);
this.finalizeSelection();
}
}
return { selectionInProgress: false, touchStartedFrom: null, isSwipe: false };
});
);
}
render() {
@ -503,5 +511,4 @@ LocationAutocompleteInputGoogleMaps.propTypes = {
inputRef: func,
};
export default LocationAutocompleteInputGoogleMaps;