Skip to content

Commit 9d5db9c

Browse files
committed
Be careful with async setState
1 parent e958d4b commit 9d5db9c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/component/PrintableItinerary.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ class PrintableItinerary extends React.Component {
379379
originalLegs={originalLegs}
380380
context={this.context}
381381
mapsLoaded={() => {
382-
this.setState({ mapsLoaded: this.state.mapsLoaded + 1 });
382+
const mapsLoaded = this.state.mapsLoaded + 1;
383+
this.setState({ mapsLoaded });
383384
if (
384-
(this.state.mapsLoaded === 1 && originalLegs.length === 1) ||
385-
this.state.mapsLoaded + 1 ===
386-
originalLegs.filter(o2 => o2.mode === 'WALK').length
385+
mapsLoaded >=
386+
originalLegs.filter(o2 => o2.mode === 'WALK').length
387387
) {
388388
setTimeout(() => window.print(), 1000);
389389
}

0 commit comments

Comments
 (0)