t49tran / react-google-recaptcha-v3

Google Recaptcha V3 integration for React
MIT License
427 stars 91 forks source link

GoogleReCaptchaProvider doesn't track reCaptchaKey change #104

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, The lib stopped working after GoogleReCaptchaProvider migration to functional component. In my case reCaptchaKey is loaded after page load and GoogleReCaptchaProvider is initialised with empty key at first. But latest version of provider doesn't track reCaptchaKey updates.

The issue could be fixed by adding reCaptchaKey to useEffect deps here https://github.com/t49tran/react-google-recaptcha-v3/blob/master/src/google-recaptcha-provider.tsx#L97

Also could I ask to add an option to disable console.warn('<GoogleReCaptchaProvider /> recaptcha key not provided') warning, as it is a normal use case to not having reCaptchaKey in some cases.

t49tran commented 2 years ago

@aleksei-savitski-softswiss thanks for the information, I will have a look. Regarding the console.warn, in the latest version, this warning message is now only shown in development build. I am also open to remove it completely or provide a way to suppress it.

t49tran commented 2 years ago

@aleksei-savitski-softswiss this problem with dynamic recaptcha key has been fixed in the latest release. For the error message, I am still considering whether should it be removed completely. I have people forgot to add the key as a props in the past and this message should help them with it. I might add an option allow the user to suppress that error message, still thinking what is the best way to do it.

ghost commented 2 years ago

@t49tran Thank you for the fix! It's totally makes sense to display a warning about missing key by default. And adding a boolean prop to disable the warning would be a backward compatible solution.