Skip to content

Commit

Permalink
Changed ref to use function instead of dep strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dozoisch committed Jun 2, 2017
1 parent 5c8a04d commit 89a1c0e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class ReCAPTCHA extends React.Component {
super();
this.state = {};
this.handleExpired = this.handleExpired.bind(this);
this.handleRecaptchaRef = this.handleRecaptchaRef.bind(this);
}

getValue() {
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class ReCAPTCHA extends React.Component {

explicitRender(cb) {
if (this.props.grecaptcha && this.state.widgetId === undefined) {
const id = this.props.grecaptcha.render(this.refs.captcha, {
const id = this.props.grecaptcha.render(this.captcha, {
sitekey: this.props.sitekey,
callback: this.props.onChange,
theme: this.props.theme,
Expand All @@ -65,13 +66,17 @@ export default class ReCAPTCHA extends React.Component {
this.explicitRender();
}

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

render() {
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
/* eslint-disable no-unused-vars */
const { sitekey, onChange, theme, type, tabindex, onExpired, size, stoken, grecaptcha, badge, ...childProps } = this.props;
/* eslint-enable no-unused-vars */
return (
<div {...childProps} ref="captcha" />
<div {...childProps} ref={this.handleRecaptchaRef} />
);
}
}
Expand Down

0 comments on commit 89a1c0e

Please sign in to comment.