appleboy/react-recaptcha

ReCAPTCHA placeholder element must be an element or id

daywong1119 opened this issue ยท 6 comments

I got the error when inflating the view by code below:

     <div className="form-group" id="captcha-holder">
        <Recaptcha sitekey="xxx" render="explicit" verifyCallback={this.onCaptchaVerify}/>
    </div>
recaptcha__en.js:286 Uncaught Error: ReCAPTCHA placeholder element must be an element or id

Several people have this problem it seems. Any advice?

Try adding onloadCallback to Recaptcha. Something similar to below

<div className="form-group" id="captcha-holder">
    <Recaptcha sitekey="xxx" render="explicit" verifyCallback={this.onCaptchaVerify} onloadCallback={this.onloadCallback}/>
</div>
wil93 commented

I solved it by adding render="explicit" and onloadCallback={console.log.bind(this, "recaptcha loaded")}

I don't know why those two things (especially the onload thing) are required, but this check may be the cause of them being required:

if (this.props.render === 'explicit' && this.props.onloadCallback) {

Thanks a lot, wil93.

#186 doesn't fix this issue. The issue doesn't present itself on hard reloads, only soft reloads when the data is already cached.

Currently using v2.3.5

I'm also having this issue in v2.3.11, but only in certain parts of my app.