0

I'm trying to add a script tag in React, <script src='https://squareup.com/appointments/buyer/widget/40tyyrjazxhd8u/B4GN8P3Q0N0Y8.js'></script>, that contains a widget from an online booking site, how would I be able to add it in React?

Thank you !

  • This may already be answered. Check out [this question](https://stackoverflow.com/questions/34424845/adding-script-tag-to-react-jsx). – Dykotomee Jul 23 '20 at 20:39

1 Answers1

1

So, something like this might work on your componentDidMount():

 componentDidMount() {
    const script = document.createElement("script");
    script.src = "https://squareup.com/appointments/buyer/widget/40tyyrjazxhd8u/B4GN8P3Q0N0Y8.js";
    script.async = true;
    document.body.appendChild(script);
 }

Here's a sandbox

Mister Pea
  • 124
  • 1
  • 4