Skip to content

Instantly share code, notes, and snippets.

@leofab86
Last active May 20, 2019 12:11
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 leofab86/6153eb054009d1f86e6ab1977d95a97c to your computer and use it in GitHub Desktop.
Save leofab86/6153eb054009d1f86e6ab1977d95a97c to your computer and use it in GitHub Desktop.
Fuzzy search autosuggest v1.2.0
//autocomplete.js
render () {
return (
<div>
<input
onChange={ e => this.setState({searchTerm: e.target.value})}
value={this.state.searchTerm}/>
<SearchResults
searchEngine={this.props.searchEngine}
searchTerm={this.state.searchTerm}/>
</div>
)
}
//searchResults.js
componentDidUpdate(prevProps) {
const {searchTerm, searchEngine} = this.props;
if(searchTerm && searchTerm !== prevProps.searchTerm) {
const setTimeoutCallback = () => {
this.setState({
searchResults: searchEngine.search(searchTerm)
})
}
setTimeout(setTimeoutCallback)
}
}
render () {
return <ReactVirtualizedList searchResults={this.state.searchResults}/>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment