-
-
Save JCaraballo113/334ef9cc730734c35331b29681cbb86b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
); | |
}; | |
const AutoTickerSearch = connectAutoComplete(TickerSearch); | |
function App() { | |
return( | |
<InstantSearch searchClient={searchClient} indexName='tickers'> | |
<AutoTickerSearch /> | |
</InstantSearch> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment