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

154
Views
React JS external script Load

I'm a beginner in React/Node.js and i got a problem on my custom shopify app dev.

i have to import, load and save an external js file on my current shoppify shop from the back.

In my react project, i could import the script via an init on button click as :

const onClick = () => {
 if (typeof window !== "undefined") {
      addScript({
        src: `https://sdk.com/loader.js`,
        id: "script",
        async: "true",

        onLoad: () => {
          console.log("script initialized!");
        },
      });
    }
  };

But when i refresh, close and reopen, i have to re-import the script.

My question is, how can i adjust my code to save the script on my DOM.

Thank you.

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

0

You can try something like this

const onClick = () => {
    const exists = document.getElementById("myScript");
    if (!exists) {
        const script = document.createElement("script");
        script.src = "https://sdk.com/loader.js";
        script.id = "myScript";
        document.body.appendChild(script);
        script.onload = () => {
            console.log("Script loaded")
        }
    }
}
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!