Skip to content

Instantly share code, notes, and snippets.

@JCaraballo113
Created August 19, 2020 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCaraballo113/d1226971d24f3f71e914a809cc6defb2 to your computer and use it in GitHub Desktop.
Save JCaraballo113/d1226971d24f3f71e914a809cc6defb2 to your computer and use it in GitHub Desktop.
import React from 'react';
import styles from '../styles/components/_tickerSearch.module.scss';
import algoliasearch from 'algoliasearch/lite';
import {
InstantSearch,
SearchBox,
Hits,
connectAutoComplete,
} from 'react-instantsearch-dom';
const searchClient = algoliasearch(
KEY_ONE_HERE,
KEY_TWO_HERE
);
const TickerSearch = ({ hits, currentRefinement, refine }: any) => {
const renderHits = () => {
return hits.map((hit: any) => <li key={hit.objectID}>{hit.symbol}</li>);
};
return (
<InstantSearch searchClient={searchClient} indexName='tickers'>
<ul>
<li>
<input
type='search'
value={currentRefinement}
onChange={(event) => refine(event.currentTarget.value)}
/>
</li>
{hits && hits.length > 0 ? renderHits() : null}
</ul>
</InstantSearch>
);
};
function Hit(props: any) {
console.log(props);
return (
<div>
<span>
{props.hit.symbol} - {props.hit.symbol_name}
</span>
</div>
);
}
export default connectAutoComplete(TickerSearch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment