Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

661
Visualizações
onChange event not working after window.reacptcha.reset() in recaptcha v2 using react-google-recaptcha npm package - [recaptcha just keeps on loading]

Im using npm react-google-recaptcha package for google recaptcha v2 check box implementation on my form page of the website

<ReCAPTCHA sitekey={KEY} onChange={this.captchaOnChange} />

once the captcha is verified Im triggering captchaOnChange function to record the response from google APIs and to set the trigger value true which is further used in my code (I have tried multiple versions of the below code with one only with async, one without async and one with async and await)

    captchaOnChange = async (value) => {
    this.setState({
      captchaValue: value,
      clicked: true,
    });
  };

And once the form is submitted Im using

window.grecaptcha.reset()

to reset the recaptcha

Now the problem is that when user clicks on the recaptcha for first time its working fine and instantly the green tick is visible on recaptcha but after submitting the form when captcha is reseted and user wants to submit the form once again and clicks on recaptcha there is no green tick, its loading continously like its trapped in some loop and also Im checking in the network tab of inspect elements there is no request being sent to any recaptcha api while its loading.

So I doubt if its some problem with onChange event after recaptcha.reset() is used, I have also found some people on internet reporting similar issue but Im not sure if its any issue or our implementation problem.

Please help!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

use it with Ref

import ReCAPTCHA from "react-google-recaptcha";
 
 
const ReCAPTCHAForm = (props) => {
  const recaptchaRef = React.useRef();
 
  const onSubmitWithReCAPTCHA = async () => {
    const token = await recaptchaRef.current.executeAsync();
 
    // apply to form data

    // reset the captcha 
    recaptchaRef.current.reset()
  }
 
  return (
    <form onSubmit={onSubmitWithReCAPTCHA}>
      <ReCAPTCHA
        ref={recaptchaRef}
        size="invisible"
        sitekey="Your client site key"
      />
    </form>
  )
 
}
 
ReactDOM.render(
  <ReCAPTCHAForm />,
  document.body
);

more info at package docs

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda