react-native-recaptcha icon indicating copy to clipboard operation
react-native-recaptcha copied to clipboard

Manually send a request to recaptcha.

Open AndreyPatseiko opened this issue 5 years ago • 2 comments

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?

AndreyPatseiko avatar May 29 '19 10:05 AndreyPatseiko

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;

lbudakov avatar Dec 24 '19 19:12 lbudakov

Use this library

https://www.npmjs.com/package/react-native-secure-captcha-v3

amitmehtacode avatar May 09 '24 19:05 amitmehtacode