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

268
Views
How to display external <script> using div in Reactjs?

I am trying to learn how to display small widgets (for example plane tickets brower) onto my website built in Reactjs. The code that's supposed to work instantly according to the provider is as below ("just copy and paste into website"):

<div id="widget" data-widget="search" data-affiliate="873" data-campaign="873-"></div>
<script src="https://widget.wakacje.pl/v2/public/js/widgets/search-widget.js?c=widget" async></script>

I tried to Google for answers and my idea atm looks like this:

function OfferBrowser() {

    const script = document.createElement("script");
    script.src = "https://widget.wakacje.pl/v2/public/js/widgets/search-widget.js?c=widget";
    script.async = true;


    return(
        <div id="widget" data-widget="search" data-affiliate="873" data-campaign="873-"></div>
    )
}

The other this I tried was also to put {script} into the tag like this, but it doesn't work as well.

<div id="widget" data-widget="search" data-affiliate="873" data-campaign="873-">{script}</div>

How should I approach this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

While I don't know React, I believe I have found the problem with the second chunk of code. You have created a script element, but have not added it to the DOM, and therefore it's not loading the script.

After looking around for a bot, I believe I've found a fix.

const script = document.createElement("script");
script.src = "https://widget.wakacje.pl/v2/public/js/widgets/search-widget.js?c=widget";
script.async = true;
// append the script tag to the body
document.body.appendChild(script);

I think this needs to run after the component is mounted, so that the div is in the DOM.

about 4 years ago · Juan Pablo Isaza Report
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!