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

178
Views
How to import external js library (cdn) to react typescript project?

I need to import https://youglish.com/public/emb/widget.js to my React project and use its YG as a function. Basically, I need this widget in my React web app. I was able to use its tag. but I need to get the YG function into React app.

you may also consider https://youglish.com/api/doc/js-api

Methods I have tried so far!

1.

import 'https://youglish.com/public/emb/widget.js'

const Widget = () => {
    const widget = new YG.Widget("widget-1");
    widget.fetch("courage", "english");
  };

  return (
    <>
      <Widget />

.....
import YG from "YG";

 useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://youglish.com/public/emb/widget.js";
    script.async = true;
    document.body.appendChild(script);
  }, []);

const Widget = () => {
    const widget = new YG.Widget("widget-1");
    widget.fetch("courage", "english");
  };

  return (
    <>
      <Widget />

.....

added in index.html dody
<script
      async
      src="https://youglish.com/public/emb/widget.js"
      charset="utf-8"
    ></script>

errors: 
Failed to compile.

./src/App.tsx
Module not found: Can't resolve 'YG' in '/Users/.../Documents/Apps/Projects/.../src'
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!