Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'clients') #294

Open
FreddieFruitSticks opened this issue Apr 30, 2024 · 3 comments
Open

Cannot read properties of undefined (reading 'clients') #294

FreddieFruitSticks opened this issue Apr 30, 2024 · 3 comments

Comments

@FreddieFruitSticks
Copy link

FreddieFruitSticks commented Apr 30, 2024

react-google-recaptcha version: 3.1.0
react-async-script version: N/A

If I load the ReCaptcha, hit submit (taking me to the next page), then click browser back, I get the following error

Cannot read properties of undefined (reading 'clients')

I've tried the following;

  1. grecaptcha.reset() the google recaptcha
  2. I tried to reload the recaptcha from the window by calling window.grecaptcha.reset()
  3. conditionally render the recaptcha based on a boolean
  4. Tried reloading the recaptcha from its ref
  const recaptchaRef = useRef(null);
  const resetCaptcha = () => {
    if (recaptchaRef.current) {
      //@ts-ignore
      recaptchaRef.current.reset();
    }
  };
  
  <ReCAPTCHA
        ref={recaptchaRef}
        hidden={!v3Failed}
        sitekey="..."
        onChange={() => {
          setV2Succeeded(true)
          resetCaptcha()
        }}
        onError={() => setV2Succeeded(false)}
        onExpired={() => setV2Succeeded(false)}
      />

@dhruvpatel2636
Copy link

i got the same error have you solved it then tell me pls how to solve this.

@FreddieFruitSticks
Copy link
Author

I eventually had to remove the component completely when navigating away from the page.

I conditionally rendered my button wrapped in the GoogleRecaptureProvider.

{activeStep === 2 ? (
                <>
                <GoogleReCaptchaProvider scriptProps={
                  {
                    async: true,
                    defer: true
                  }
                } reCaptchaKey="...">

                 <SubmitButton/>
                </GoogleReCaptchaProvider>
              </>
            ) : <Button>
                    Next
                </Button>}

@yuenu
Copy link

yuenu commented Aug 22, 2024

If you are using antd's Modal component and encounter issues with delayed rendering or state inconsistency, try adding the forceRender property.

ref

<Modal forceRender {...otherProps}> // add here
  <Form>
     {/* Modal Content */}
  </Form>
</Modal>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants