react-native-recaptcha
react-native-recaptcha copied to clipboard
Manually send a request to recaptcha.
How can I delay my request for a recaptcha token? I got response token after recaptcha was loading, for now. But I need execute recaptcha only when user fill my form. How I can do this?
You can achieve that the following way:
The below example code is not tested but the idea is the following
When the button is clicked the captcha is loaded and once the token is received the actual process that requires the captcha is started.
class Example extends Component {
constructor(props) {
super(props)
this.state = {
loadCaptcha: false
}
}
handlePress = () => {
this.setState({ loadCaptcha: true })
}
handleReCaptchaExecute = (captcha) => {
this.setState({ loadCaptcha: false });
// Do whatever you want to do with the captcha
}
render() {
const { loadCaptcha } = this.state;
const captchaComponent = (
<View style={{ width: '100%', height: 0 }}>
<ReCaptcha
siteKey="SITEKEYHERE"
url="URLHERE"
action="verify"
reCaptchaType={1} // invisible
onExecute={this.handleReCaptchaExecute}
/>
</View>
);
return (
{loadCaptcha && captchaComponent}
<Button
title="Press me"
color="#f194ff"
onPress={this.handlePress}
/>
)
}
}
export default Example;
Use this library
https://www.npmjs.com/package/react-native-secure-captcha-v3