siberiacancode / google-recaptcha

🔑 tool that easily and quickly add Google ReCaptcha for your website or application
https://www.npmjs.com/package/@google-recaptcha/react
MIT License
47 stars 1 forks source link

Passing callback or expiredCallback to GoogleReCaptchaCheckbox shows an error in console #3

Closed AlphaSteam closed 2 months ago

AlphaSteam commented 3 months ago

When passing callback or expiredCallback to the GoogleReCaptchaCheckbox component the errors:

Invalid value for prop `callback` on <div> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM

and

Warning: React does not recognize the `expiredCallback` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `expiredcallback` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Are shown respectively.

This happens because in GoogleReCaptchaCheckbox there's a {...props} in the div.

debabin commented 3 months ago

Thanks @AlphaSteam for using our library, we were not only able to remove the warning, but also fixed 'expired-callback' and 'error-callback', they did not work before

debabin commented 3 months ago

You can check this in release 1.0.4 of react package

AlphaSteam commented 3 months ago

Hi! Thanks for answering.

The error is gone with expired and error callbacks and they are working.

I'm still getting the error with callback though. It says Invalid value for prop "callback" on <div> tag and the callback is not working.

Here is my current implementation


<GoogleReCaptchaCheckbox
      {...props}
      callback={(token)=>{
        localStorage.setItem('recaptcha-v2-token', token);
        if (callback) callback();
      }}
      expiredCallback={()=>{
        localStorage.removeItem('recaptcha-v2-token');
        if (expiredCallback) expiredCallback();
      }}
      errorCallback={()=>{
        localStorage.removeItem('recaptcha-v2-token');
        if (errorCallback) errorCallback();
      }}
    />```
debabin commented 3 months ago

image

Hi, this is very strange because when typing a checkbox there is no callback anymore, you need to use onChange