t49tran / react-google-recaptcha-v3

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

Token generated at rapid pace in Next.js app #53

Closed prateem closed 3 years ago

prateem commented 3 years ago

Hi there! I'm using this package in a Next.js app and find that on the page where I have the <GoogleReCaptcha> component placed, the onVerify callback is called very rapidly and new tokens are constantly generated.

I just wanted to know if this is expected.

I'm not doing anything fancy with the component, but here's what the code looks like (roughly):

export default function Contact() {
  const [token, setToken] = useState(null);

  return (
    <>
      // ...
      <GoogleReCaptcha onVerify={ (token) => { setToken(token); console.log(token); } } />
    </>
  );
};
t49tran commented 3 years ago

@prateem, please read the document.

https://github.com/t49tran/react-google-recaptcha-v3#googlerecaptcha

Your code is exactly a common mistake that I have documented and say should be avoided.