Usage
$ npm i algoliasearch algolia-react-autocomplete"
; ;; // init algoliasearch sdk and indexesconst client = ;const indexes = source: thisclient displayKey: 'name' templates: <h2 className="aa-suggestions-category"> Players</h2> <div data-selected=isSelected> suggestionname </div> // in your render method<Autocomplete indexes=indexes onSelectionChange= console> <input key="input" type="search" className="aa-input-search" autocomplete="off" /></Autocomplete>
Run demo
$ git clone https://github.com/tkrugg/algolia-react-autocomplete.git$ cd algolia-react-autocomplete$ npm i$ npm start
There is a demo hosted here: https://codesandbox.io/s/kk4v5nqrz5
FAQ
why do I have to install algoliasearch myself, can't I just pass in my credentials inside the component
You're right. This component makes assumptions on the algolia sdk it's being passed, embedding the lib is safer. But I'm suspecting the user might be using this same sdk as a data source for other components. This is more flexible.
CSS is for dummies, why not inline styles?
CSS classes are easier and faster to override. With inline styles we'd have to expose every style attribute under that piece of DOM. Plus, I just hate inline styles :troll:. Please try to change my mind, don't give up on me.
Credits
This component was started off this boilerplate: https://github.com/DimiMikadze/create-react-library