Skip to content

Commit

Permalink
Merge pull request dozoisch#73 from jhrdina/fix_#55
Browse files Browse the repository at this point in the history
Remove rendered DOM on unmount
  • Loading branch information
dozoisch authored Mar 25, 2018
2 parents 73edf7f + e881943 commit 8c6a8dc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default class ReCAPTCHA extends React.Component {

explicitRender(cb) {
if (this.props.grecaptcha && this.state.widgetId === undefined) {
const id = this.props.grecaptcha.render(this.captcha, {
const wrapper = document.createElement("div");
const id = this.props.grecaptcha.render(wrapper, {
sitekey: this.props.sitekey,
callback: this.props.onChange,
theme: this.props.theme,
Expand All @@ -61,6 +62,8 @@ export default class ReCAPTCHA extends React.Component {
stoken: this.props.stoken,
badge: this.props.badge,
});
this.captcha.appendChild(wrapper);

this.setState({
widgetId: id,
}, cb);
Expand All @@ -79,6 +82,15 @@ export default class ReCAPTCHA extends React.Component {
this.explicitRender();
}

componentWillUnmount() {
if (this.state.widgetId !== undefined) {
while (this.captcha.firstChild) {
this.captcha.removeChild(this.captcha.firstChild);
}
this.reset();
}
}

handleRecaptchaRef(elem) {
this.captcha = elem;
}
Expand Down

0 comments on commit 8c6a8dc

Please sign in to comment.