Skip to content

Commit

Permalink
fix the error when change props (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuboaibc authored and DSergiu committed Feb 2, 2021
1 parent ca655ab commit 9129e25
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ class HCaptcha extends React.Component {

// If they have changed, remove current captcha and render a new one
if (!match) {
this.removeCaptcha();
this.renderCaptcha();
this.removeCaptcha(() => {
this.renderCaptcha();
});
}
}

Expand Down Expand Up @@ -134,13 +135,14 @@ class HCaptcha extends React.Component {
hcaptcha.reset(captchaId)
}

removeCaptcha() {
removeCaptcha(callback) {
const { isApiReady, isRemoved, captchaId } = this.state;

if (!isApiReady || isRemoved) return

this.setState({ isRemoved: true }, () => {
hcaptcha.remove(captchaId);
callback && callback()
});
}

Expand Down

0 comments on commit 9129e25

Please sign in to comment.