Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

423
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!