1

Im using npm react-google-recaptcha package for google recaptcha v2 check box implementation on my form page of the website

<ReCAPTCHA sitekey={KEY} onChange={this.captchaOnChange} />

once the captcha is verified Im triggering captchaOnChange function to record the response from google APIs and to set the trigger value true which is further used in my code (I have tried multiple versions of the below code with one only with async, one without async and one with async and await)

    captchaOnChange = async (value) => {
    this.setState({
      captchaValue: value,
      clicked: true,
    });
  };

And once the form is submitted Im using

window.grecaptcha.reset()

to reset the recaptcha

Now the problem is that when user clicks on the recaptcha for first time its working fine and instantly the green tick is visible on recaptcha but after submitting the form when captcha is reseted and user wants to submit the form once again and clicks on recaptcha there is no green tick, its loading continously like its trapped in some loop and also Im checking in the network tab of inspect elements there is no request being sent to any recaptcha api while its loading.

So I doubt if its some problem with onChange event after recaptcha.reset() is used, I have also found some people on internet reporting similar issue but Im not sure if its any issue or our implementation problem.

Please help!!

1
  • Also I would like to add that I'm facing this problem all of sudden, It was running fine 2 days back and it had once shown this error "recaptcha__en.js:120 uncaught (in promise) rangeerror: maximum call stack size exceeded" but at this time it took lot of time for loading but finally there was green tick, but now its just continously loading and there is no error nor anything else Commented Sep 10, 2021 at 8:18

1 Answer 1

0

use it with Ref

import ReCAPTCHA from "react-google-recaptcha";
 
 
const ReCAPTCHAForm = (props) => {
  const recaptchaRef = React.useRef();
 
  const onSubmitWithReCAPTCHA = async () => {
    const token = await recaptchaRef.current.executeAsync();
 
    // apply to form data

    // reset the captcha 
    recaptchaRef.current.reset()
  }
 
  return (
    <form onSubmit={onSubmitWithReCAPTCHA}>
      <ReCAPTCHA
        ref={recaptchaRef}
        size="invisible"
        sitekey="Your client site key"
      />
    </form>
  )
 
}
 
ReactDOM.render(
  <ReCAPTCHAForm />,
  document.body
);

more info at package docs

2
  • Could you please explain how would using create a difference or why I might be facing the issue Commented Sep 10, 2021 at 8:48
  • I don't have enough info on why you are facing this issue, I think your component is rerendering multiple times.
    – Talha
    Commented Sep 10, 2021 at 9:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.