ppshein ppshein - 1 year ago 87
React JSX Question

How to include external javascript library in PreactJS?

I'm currently one small project based on preactJS with algolia? I found that there is algolia component for reactjs but unfortunately, no algolia component for preactjs. That's why my problem is how can I include algolia javascript file into preactjs?

<script src="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>

Answer Source

You can insert script dynamically, try this one:

componentWillMount() {
    const script = document.createElement("script");
    script.src = "https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js";
    script.async = true;

    script.onload = function() {
       // init your algolia code here
    }

    document.body.appendChild(script);
},
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download