I'm using Algolia for autocomplete inside my React app. But I encountered a few problems during development:
I'm using the algoliasearch/lite
and react-instantsearch-dom
package.
currentRefinement
is not empty:
import { connectAutoComplete } from 'react-instantsearch-dom';
const Autocomplete = ({ hits, currentRefinement, refine }) => (
<ul>
<li>
<input
type="search"
value={currentRefinement}
onChange={event => refine(event.currentTarget.value)}
/>
</li>
//Render only if currentRefinement not empty
{currentRefinement && (
hits.map(hit => (
<li key={hit.objectID}>{hit.name}</li>
))
)}
</ul>
);
const CustomAutocomplete = connectAutoComplete(Autocomplete);
SearchBox
example code the documentation