Last active
May 20, 2019 12:04
-
-
Save leofab86/f3669aa70ddb2f13509bbd53d9eb7e4d to your computer and use it in GitHub Desktop.
Fuzzy search autocomplete v1.2.4
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
//searchResults.js | |
export default class SearchResults extends React.Component { | |
constructor (props) { | |
super(); | |
this.state = { | |
searchResults: [], | |
} | |
//initiate the worker array: | |
this.workerArray = new WorkerArrayController({ | |
data: props.data, | |
handleResults: this.handleResults, | |
arraySize: 4 | |
}); | |
} | |
componentDidUpdate(prevProps) { | |
const {searchTerm} = this.props; | |
if(searchTerm && searchTerm !== prevProps.searchTerm) { | |
this.workerArray.search({searchTerm}) | |
} | |
} | |
handleResults = (e) => { | |
const {searchResults} = e.data | |
this.setState({ | |
searchResults | |
}) | |
} | |
componentWillUnmount () { | |
this.workerArray.terminate(); | |
} | |
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