如何添加谷歌recaptcha创建反应的应用程序?
问题描述:
我试图让recaptcha响应,以便我可以通过redux-form
传递它。
已尝试下列2种方法...如何添加谷歌recaptcha创建反应的应用程序?
尝试1:
在<head>
指定回调。
的index.html:
<script src='https://www.google.com/recaptcha/api.js?onload=callback&render=explicit'></script>
这里的问题是,回调是在全球范围内,但我需要访问它在反应的组分。
尝试2:
指定DOM中的回调。
元器件:handleRecaptcha(RESP)
handleRecaptcha(resp) {
console.log(resp);
}
元器件:渲染():
<div className="g-recaptcha" data-callback={this.handleRecaptcha.bind(this)} data-sitekey="***"></div>
的index.html:
<script src='https://www.google.com/recaptcha/api.js'></script>
提交recaptcha后,我收到消息ReCAPTCHA couldn't find user-provided function: function() { [native code] }
。可能也是一个范围问题。
我试图避免使用另一个库,因为我认为这是一个相当微不足道的问题。
会有人想知道如何去解决吗?
我所需要的只是掌握widget
实例,并做grecaptcha.getResponse(widget)
来获得响应。 API ref
答
import Recaptcha from 'react-recaptcha'
<Recaptcha
sitekey="xxxxxxxxxxxxxxxxxxxx"
render="explicit"
verifyCallback={verifyCallback}
onloadCallback={callback}
/>
雅这其中也可以替代。我现在使用它 –