react-typeahead
react-typeahead copied to clipboard
How to implement search matching sort function?
I have this function which
_handleSort = (a, b, input_string) => {
let distance = this.levenshtein.get(a.name, input_string) - this.levenshtein.get(b.name, input_string)
console.log(`a:${a.name}, b:${b.name}, input:${input_string}`)
return distance;
}
How can I make it so that the results are sorted by this function as I type in the AsyncTypeAhead
something like this?
<AsyncTypeahead
onSearch={this._handleSearch}
searchOptions={this._handleSort}
...
_handleSort = (value, options) => {
let sorter = (a, b) => {
let distance = this.levenshtein.get(a.name, value) - this.levenshtein.get(b.name, value)
console.log(`a:${a.name}, b:${b.name}, input:${value}`)
return distance;
}
return options.sort(sorter)
}
it doesn't seem like the sorter function is ever getting called