I'm currently one small project based on preactJS with algolia? I found that there is algolia ponent for reactjs but unfortunately, no algolia ponent for preactjs. That's why my problem is how can I include algolia javascript file into preactjs?
<script src=".js/1/instantsearch.min.js"></script>
I'm currently one small project based on preactJS with algolia? I found that there is algolia ponent for reactjs but unfortunately, no algolia ponent for preactjs. That's why my problem is how can I include algolia javascript file into preactjs?
<script src="https://cdn.jsdelivr/instantsearch.js/1/instantsearch.min.js"></script>
Share
Improve this question
edited Aug 16, 2017 at 9:11
Pyae Phyoe Shein
asked Aug 16, 2017 at 8:35
Pyae Phyoe SheinPyae Phyoe Shein
13.8k47 gold badges152 silver badges243 bronze badges
4
- Also, I don't know if you see it but we have another flavor of InstantSearch, React-InstantSearch, that might integrate better with your preact app. Don't hesitate to give us your feedback about it. – Marie Commented Aug 16, 2017 at 11:25
-
@Marie I've tried with
React-InstantSearch
but when I rendered, I've encounteredprocess
error. That's why I've gave it up. – Pyae Phyoe Shein Commented Aug 17, 2017 at 4:47 - Could you open an issue on our github repository with the error you encountered? We need to investigate about that :) – Marie Commented Aug 17, 2017 at 7:55
- @Marie sure, I've created ticket. github./algolia/react-instantsearch/issues/264 – Pyae Phyoe Shein Commented Aug 18, 2017 at 2:28
4 Answers
Reset to default 4Preact has ponent 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/instantsearch.js/1/instantsearch.min.js"></script>
</Head>
</div>
);
}
}
You can insert script dynamically, try this one:
ponentWillMount() {
const script = document.createElement("script");
script.src = "https://cdn.jsdelivr/instantsearch.js/1/instantsearch.min.js";
script.async = true;
script.onload = function() {
// init your algolia code here
}
document.body.appendChild(script);
},
You can install the package algoliasearch (if package is not correct, just search the desired package at https://npmjs.)
Now you can do npm install algoliasearch --save
at your root level where package.json is there and use it in your module like following -
import algolia from 'algolia';
And then use its methods in your code.
You can just add it in your index.html between the head tags.
In React, the index.html is in public/index.html
In Preact, index.html is in src/index.html
<head>
<script src="https://cdn.jsdelivr/instantsearch.js/1/instantsearch.min.js"></script>
</head>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744795346a4594173.html
评论列表(0条)