Skip to content

Commit 54752e8

Browse files
fix(aftershow): call afterShow only after state has fully updated
1 parent 8d260dc commit 54752e8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: src/index.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,11 @@ class ReactTooltip extends React.Component {
581581
show: true
582582
},
583583
() => {
584-
this.updatePosition();
585-
if (isInvisible && afterShow) {
586-
afterShow(e);
587-
}
584+
this.updatePosition(() => {
585+
if (isInvisible && afterShow) {
586+
afterShow(e);
587+
}
588+
});
588589
}
589590
);
590591
}
@@ -692,7 +693,7 @@ class ReactTooltip extends React.Component {
692693
}
693694

694695
// Calculation the position
695-
updatePosition() {
696+
updatePosition(callbackAfter) {
696697
const {
697698
currentEvent,
698699
currentTarget,
@@ -727,10 +728,12 @@ class ReactTooltip extends React.Component {
727728
if (result.isNewState) {
728729
// Switch to reverse placement
729730
return this.setState(result.newState, () => {
730-
this.updatePosition();
731+
this.updatePosition(callbackAfter);
731732
});
732733
}
733734

735+
callbackAfter();
736+
734737
// Set tooltip position
735738
node.style.left = result.position.left + 'px';
736739
node.style.top = result.position.top + 'px';

0 commit comments

Comments
 (0)