react-select-fast-filter-options
Fast filterOptions
function for react-select
;
optimized to quickly filter huge options lists.
Getting started
Installation
The easiest way to install is using NPM:
npm install react-select-fast-filter-options --save
ES6, CommonJS, and UMD builds are available with each distribution.
Use unpkg to access the UMD build:
<script src="https://unpkg.com/react-select-fast-filter-options/dist/umd/react-select-fast-filter-options.js"></script>
Here's how to fast filter with react-select
or react-virtualized-select
:
import Select from 'react-virtualized-select'
import createFilterOptions from 'react-select-fast-filter-options'
const filterOptions = createFilterOptions({ options })
function render ({ options }) {
return (
<Select
filterOptions={filterOptions}
options={options}
{...otherSelectProps}
/>
)
}
Configuration Options
By default, createFilterOptions
returns a filter function configured to match all substrings, in a case-insensitive way, and return results in their original order. However it supports all of the underlying js-search
configuration options.
The following table shows all supported parameters and their default values:
Advanced Configuration
The default filter configuration mimics react-search
behavior.
But you can also customize search.
For example:
import {
CaseSensitiveSanitizer,
ExactWordIndexStrategy,
Search,
SimpleTokenizer,
StemmingTokenizer,
TfIdfSearchIndex
} from 'js-search'
import { stemmer } from 'porter-stemmer'
import createFilterOptions from 'react-select-fast-filter-options'
const indexStrategy = new ExactWordIndexStrategy()
const sanitizer = new CaseSensitiveSanitizer()
const searchIndex = new TfIdfSearchIndex()
const tokenizer = new StemmingTokenizer(stemmer, new SimpleTokenizer())
const filterOptions = createFilterOptions({
indexStrategy,
options,
sanitizer,
searchIndex,
tokenizer
})
In addition to the stemming tokenizer, other tokenizers are available as well, including StopWordsTokenizer
which removes common words like "a", "and", and "the".
For more information on available configuration options, see js-search
documentation.