question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invisible captcha badge not rendering again after just unmounting

See original GitHub issue

react-google-recaptcha version: 2.0.1

export const ReCaptcha = memo(function Recaptcha({ onChange }) {
  const recaptchaRef = useRef();

  function handleError(err) {
    console.log("Error in recaptcha", err);
  }

  return (
    <ReCAPTCHA
      ref={recaptchaRef}
      sitekey={RECAPTCHA_SITE_KEY}
      size="invisible"
      badge="bottomright"
      onChange={onChange}
      onErrored={handleError}
    />
  );
});

Here is my wrapper on recaptcha. I render this inside a div and the content inside the div unmounts and mounts on a certain user action.

Issue is if the content inside mounted immediately after unmounting, then invisible captcha works fine but the badge doesnt render, rather it is hidden and renders inline but hidden. But if it is mounted after 5-6 seconds after unmounting, then it renders at bottomright of div.

What i have tried:

useEffect(()=>{
   setTimeout(() => {window.grecaptcha.reset();}, 1000)
}, [])

If i run from browser console window, it resets and captcha is rendered agains, but doing it on mount is not working.

Any help would be much appreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

6reactions
davidebotcommented, Sep 29, 2020

Hello everybody! Does anyone found a fix to this issue?

1reaction
UseMusecommented, May 23, 2020

@cw-amitsingh ХО-amitsingh it helped me

 function onChange(value) {
        //custom fetch and at the end do a reset
       if (recaptchaRef && recaptchaRef.current && recaptchaRef.current.reset) {
            recaptchaRef.current.reset()
        }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Google "reCaptcha" sometimes doesn't get displayed/rendered
This problem appeared with me in google maps when initializing the map on hidden div (e.g. a modal). I'd solve this problem by...
Read more >
Frequently Asked Questions | reCAPTCHA - Google Developers
Simply use the JavaScript API to explicitly render reCAPTCHA with a v3 site key to access options such as repositioning the badge or...
Read more >
Google no Captcha + INVISIBLE reCaptcha - TehnoBlog
Google now officially allows hiding the reCaptcha badge IF AND ONLY IF you post this text below the submit/sign-in/registration/comment/etc.
Read more >
react-google-recaptcha - Bountysource
Invisible captcha badge not rendering again after just unmounting $ 0. Created 2 years ago in dozoisch/react-google-recaptcha with 8 comments. react-google- ...
Read more >
react-google-recaptcha | Yarn - Package Manager
With the invisible option, you need to handle things a bit differently. You will need to call the execute method yourself. import ReCAPTCHA...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found