Skip to content

Instantly share code, notes, and snippets.

@leofab86
Last active May 23, 2019 17:05
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/9a8db408da2eede6cb1c80f515fe7fec to your computer and use it in GitHub Desktop.
Save leofab86/9a8db408da2eede6cb1c80f515fe7fec to your computer and use it in GitHub Desktop.
Fuzzy search autocomplete v1.1.1
//searchResults.js
componentDidUpdate(prevProps) {
const {searchTerm, searchEngine} = this.props;
if(searchTerm && searchTerm !== prevProps.searchTerm) {
/* stick the update with the expensive search method into
a setTimeout callback: */
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