简体   繁体   中英

How to use Eventbrite's Embedded Widget with React/JSX?

EventBrite's popup widget isn't compatible with React / JSX / GatsbyJs. Looking for help on how to appropriately implement this on a Gatsby site. If you've done this before, what did you do? This is the code they give:

<button id="example-widget-trigger" type="button">Buy Tickets</button>

<script src="https://www.eventbrite.com/static/widgets/eb_widgets.js"></script>

<script type="text/javascript">
  var exampleCallback = function() {
    console.log("Order complete!");
  };

  window.EBWidgets.createWidget({
    widgetType: "checkout",
    eventId: "52766401728",
    modal: true,
    modalTriggerElementId: "example-widget-trigger",
    onOrderComplete: exampleCallback
  });
</script>

First run command cp .cache/default-html.js src/html.js in root of gatsby project in terminal

It will get access to html.js file. There you can put code you need like this:

<script src="https://www.eventbrite.com/static/widgets/eb_widgets.js"></script>

<script
    dangerouslySetInnerHTML={{
        __html: `
            var exampleCallback = function() {
              console.log("Order complete!");
            };

            window.EBWidgets.createWidget({
              widgetType: "checkout",
              eventId: "52766401728",
              modal: true,
              modalTriggerElementId: "example-widget-trigger",
              onOrderComplete: exampleCallback
            });
        `
    }}
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM