antokara / react-recaptcha-x

a React reCAPTCHA version 3 and version 2 (checkbox) component in one.
MIT License
23 stars 11 forks source link

ReCaptcha V2 is not rendered if provider and comsumer is not rendered at the same time #27

Closed denke8 closed 4 years ago

denke8 commented 4 years ago

Describe the bug If you use the widget like the example show, it works correctly, but if you want to use it in a more complex app, which uses somekind of router, put the provider around the router and later navigate to a route which renders the recaptcha, is not rendered.

To Reproduce -Run create react app -replace the content of app.js with the following:

import React, { useState, useEffect } from "react";
import { ReCaptchaProvider, ReCaptchaV2 } from "react-recaptcha-x";

const delay = 500;

function App() {
  const [show, setShow] = useState(false);

  useEffect(() => {
    setTimeout(() => setShow(true), delay);
  }, []);

  return (
    <div>
      <ReCaptchaProvider siteKeyV2="KEY">
        {show && (
          <>
            rendered
            <ReCaptchaV2 callback={() => {}} />
          </>
        )}
      </ReCaptchaProvider>
    </div>
  );
}

export default App;

Expected behavior the recaptcha whould render

Actual If you set delay to ~50 it works, if tou set it to ~500 it does not. I guess it depends on when the google recaptcha script (added by this lib) loads

Desktop

antokara commented 4 years ago

thank you @denesstreambright for the report, I'll try to fix it quickly.

antokara commented 4 years ago

@denesstreambright I just released v1.1.4 with the fix https://www.npmjs.com/package/react-recaptcha-x/v/1.1.4

please let me know if the issue persists. Thanks again and if you like this package, consider starring it, to support it and help others find it.

denke8 commented 4 years ago

Thanks for the quick fix, it works now!