Last active
May 20, 2019 12:11
-
-
Save leofab86/6153eb054009d1f86e6ab1977d95a97c to your computer and use it in GitHub Desktop.
Fuzzy search autosuggest v1.2.0
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
//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