Skip to content

Commit 89a1c0e

Browse files
committed
Changed ref to use function instead of dep strings
1 parent 5c8a04d commit 89a1c0e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/recaptcha.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class ReCAPTCHA extends React.Component {
66
super();
77
this.state = {};
88
this.handleExpired = this.handleExpired.bind(this);
9+
this.handleRecaptchaRef = this.handleRecaptchaRef.bind(this);
910
}
1011

1112
getValue() {
@@ -40,7 +41,7 @@ export default class ReCAPTCHA extends React.Component {
4041

4142
explicitRender(cb) {
4243
if (this.props.grecaptcha && this.state.widgetId === undefined) {
43-
const id = this.props.grecaptcha.render(this.refs.captcha, {
44+
const id = this.props.grecaptcha.render(this.captcha, {
4445
sitekey: this.props.sitekey,
4546
callback: this.props.onChange,
4647
theme: this.props.theme,
@@ -65,13 +66,17 @@ export default class ReCAPTCHA extends React.Component {
6566
this.explicitRender();
6667
}
6768

69+
handleRecaptchaRef(elem) {
70+
this.captcha = elem;
71+
}
72+
6873
render() {
6974
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
7075
/* eslint-disable no-unused-vars */
7176
const { sitekey, onChange, theme, type, tabindex, onExpired, size, stoken, grecaptcha, badge, ...childProps } = this.props;
7277
/* eslint-enable no-unused-vars */
7378
return (
74-
<div {...childProps} ref="captcha" />
79+
<div {...childProps} ref={this.handleRecaptchaRef} />
7580
);
7681
}
7782
}

0 commit comments

Comments
 (0)