Comments (4)
plugins is an argument to createAutocomplete
, so you pass the argument on to that call. Would that work?
from autocomplete.
How would you implement it in this code:
[https://www.algolia.com/doc/ui-libraries/autocomplete/guides/creating-a-renderer/]
I would like to pass it down the props like function Autocomplete({plugins}) ... Just like you would do with the default @algolia/autocomplete-js
`const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);
function Autocomplete() {
// (1) Create a React state.
const [autocompleteState, setAutocompleteState] = React.useState({});
const autocomplete = React.useMemo(
() =>
createAutocomplete({
onStateChange({ state }) {
// (2) Synchronize the Autocomplete state with the React state.
setAutocompleteState(state);
},
getSources() {
return [
// (3) Use an Algolia index source.
{
sourceId: 'products',
getItemInputValue({ item }) {
return item.query;
},
getItems({ query }) {
return getAlgoliaResults({
searchClient,
queries: [
{
indexName: 'instant_search',
query,
params: {
hitsPerPage: 4,
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
},
},
],
});
},
getItemUrl({ item }) {
return item.url;
},
},
];
},
}),
[]
);
// ...
}`
from autocomplete.
Something like this:
const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);
function Autocomplete({plugins}) {
// (1) Create a React state.
const [autocompleteState, setAutocompleteState] = React.useState({});
const autocomplete = React.useMemo(
() =>
createAutocomplete({
plugins, // could be static here too
onStateChange({ state }) {
// (2) Synchronize the Autocomplete state with the React state.
setAutocompleteState(state);
},
getSources() {
return [
// (3) Use an Algolia index source.
{
sourceId: 'products',
getItemInputValue({ item }) {
return item.query;
},
getItems({ query }) {
return getAlgoliaResults({
searchClient,
queries: [
{
indexName: 'instant_search',
query,
params: {
hitsPerPage: 4,
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
},
},
],
});
},
getItemUrl({ item }) {
return item.url;
},
},
];
},
}),
[]
);
// ...
}`
from autocomplete.
Okay thanks but it gives me this output. The dropdown is empty(The four search results is the Instant_search), as you can see on the pic. and thats after a couple of search it's till empty.... Should i provide any of the jsx? shouldn't that come with the import { createLocalStorageRecentSearchesPlugin } from '@algolia/autocomplete-plugin-recent-searches'; ?
And it works fine if I use the autocomplete build by algolia
from autocomplete.
Related Issues (20)
- `id` setting should apply to the form element too
- Set search input height in Parcel bundler. HOT 4
- onSelect() called after getSources(), causing a closing delay of the dropdown
- Sending events in the render function
- aria-labelledby on the input element fails WCAG checks because the target button has no text
- Detached mode - entered text is present in two places HOT 1
- Korean text disappears from the input box. HOT 11
- In detached mode when there are no items, the dropdown still appears HOT 4
- VUE Autocomplete return instead of JSX from a VUE Component HOT 1
- Autocomplete box doesn't work with fixed positioning HOT 1
- Autocomplete returning empty result HOT 1
- onSelect item should trigger store.pendingRequests.cancelAll(); HOT 1
- `yarn add @algolia/autocomplete-js` produces a bunch of unmet peer dependency warnings HOT 2
- Migration from 0 to v1 is about to end my reliance on this control HOT 1
- Autocomplete panel not close on clicking outside in react 18 HOT 5
- "insight:true" shows error in createAutocomplete with NextJS React18 HOT 2
- Issue in Autocomplete inside custom element (web component) using React instant search
- Autocomplete Plugin: createQuerySuggestionsPlugin no support in React 18.
- TypeError: Cannot read properties of null (onKeyDown.js) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autocomplete.