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

426
Visualizações
Grecaptcha is not defined in document | React script

I have the following function that's executed whenever recaptcha should be used. The problem is that the script is not ready or is not yet appended as child when I want to use grecaptcha. Document.createElement("recaptcha_script") is always null when I want to use it. I'm not sure if there is a better way or a solution to my problem. I don't want to use a npm package.

export const RecaptchaAPI = async () => {

const recaptchaScript = async () => {
    const script = document.createElement("recaptcha_script");
    script.src =`https://www.google.com/recaptcha/api.js?render=${process.env.REACT_APP_RECAPTCHA_SITE_KEY}`;
    script.async = true;
    document.body.appendChild(script);
    script.onload = recaptchaRequest();
}

const recaptchaRequest = () => {
    const element = document.getElementById("recaptcha_script");
    element.grecaptcha.ready(() => {
        element.grecaptcha.execute('reCAPTCHA_site_key').then((token) => {
            console.log("worked");
        });
    });
}

return await recaptchaScript()}
about 4 years ago · Juan Pablo Isaza
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