Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 212
PPShein Avatar asked Mar 13 '26 00:03

PPShein


1 Answers

Preact has component Head. To install it run

yarn add preact-head

Then it will be possible to specify standard head element such as script, meta, etc.. E.x. app.js

import Head from "preact-head";

export default class App extends Component {

        render() {
            return (
                <div id="app">
                    <Head>
                        <meta name="Whatever" />
                        <script src="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
                    </Head>

                </div>
            );
        }
    }
like image 182
Mara Avatar answered Mar 15 '26 13:03

Mara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!