From 54752e81093f4c41bae1b49f7de65f28cf54df1a Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Wed, 9 Feb 2022 15:16:28 +0000 Subject: [PATCH] fix(aftershow): call afterShow only after state has fully updated --- src/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index bc985c49a..b32061718 100755 --- a/src/index.js +++ b/src/index.js @@ -581,10 +581,11 @@ class ReactTooltip extends React.Component { show: true }, () => { - this.updatePosition(); - if (isInvisible && afterShow) { - afterShow(e); - } + this.updatePosition(() => { + if (isInvisible && afterShow) { + afterShow(e); + } + }); } ); } @@ -692,7 +693,7 @@ class ReactTooltip extends React.Component { } // Calculation the position - updatePosition() { + updatePosition(callbackAfter) { const { currentEvent, currentTarget, @@ -727,10 +728,12 @@ class ReactTooltip extends React.Component { if (result.isNewState) { // Switch to reverse placement return this.setState(result.newState, () => { - this.updatePosition(); + this.updatePosition(callbackAfter); }); } + callbackAfter(); + // Set tooltip position node.style.left = result.position.left + 'px'; node.style.top = result.position.top + 'px';