• Stars
    star
    206
  • Rank 184,217 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

react-select filterOptions function optimized to quickly filter large options lists

react-select-fast-filter-options

Fast filterOptions function for react-select; optimized to quickly filter huge options lists.

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>

Examples

react-select example

Try this example in Code Sandbox.

// Import default styles.
// This only needs to be done once; probably during bootstrapping process.
import "react-select/dist/react-select.css";

import React from "react";
import ReactDOM from "react-dom";
import createFilterOptions from "react-select-fast-filter-options";
import Select from "react-select";

// Dummy array of test values.
const options = [
  {label: "Option One", value: 1},
  {label: "Option Two", value: 2},
];

// For more configuration options, see:
// https://github.com/bvaughn/react-select-fast-filter-options#configuration-options
const filterOptions = createFilterOptions({
  options
});

ReactDOM.render(
  <Select filterOptions={filterOptions} options={options} />,
  document.getElementById("root")
);

react-virtualized-select example

Try this example in Code Sandbox.

// Import default styles.
// This only needs to be done once; probably during bootstrapping process.
import "react-select/dist/react-select.css";
import "react-virtualized/styles.css";
import "react-virtualized-select/styles.css";

import React from "react";
import ReactDOM from "react-dom";
import createFilterOptions from "react-select-fast-filter-options";
import Select from "react-virtualized-select";

// Dummy array of test values.
const options = [
  {label: "Option One", value: 1},
  {label: "Option Two", value: 2},
];

// For more configuration options, see:
// https://github.com/bvaughn/react-select-fast-filter-options#configuration-options
const filterOptions = createFilterOptions({
  options
});

ReactDOM.render(
  <Select filterOptions={filterOptions} options={options} />,
  document.getElementById("root")
);

react-redux example

Try this example in Code Sandbox.

selectors.js
// selectors file
import { createSelector } from "reselect";
import createFilterOptions from "react-select-fast-filter-options";

// Select the huge array of options stored in redux state
export const optionsSelector = state => state.options;

// Create a search index optimized to quickly filter options.
// The search index will need to be recreated if your options array changes.
// This index is powered by js-search: https://github.com/bvaughn/js-search
// Reselect will only re-run this if options has changed
export const getIndexedOptions = createSelector(optionsSelector, options =>
  createFilterOptions({ options })
);
reducers.js
// Dummy array of test values.
const options = Array.from(new Array(100), (_, index) => ({
  label: `Item ${index}`,
  value: index
}));

const INITIAL_STATE = {
  options
};

function searchApp(state = INITIAL_STATE, action) {
  switch (action.type) {
    default:
      return state;
  }
}

export default searchApp;
application.js
// Import default styles.
// This only needs to be done once; probably during bootstrapping process.
import "react-select/dist/react-select.css";

import React from "react";
import ReactDOM from "react-dom";
import { connect, Provider } from "react-redux";
import Select from "react-select";
import { createStore } from "redux";
import { createSelector } from "reselect";
import searchApp from "./reducers";
import { getIndexedOptions, optionsSelector } from "./selectors";

const store = createStore(searchApp);
const mapStateToProps = state => ({
  filterOptions: getIndexedOptions(state),
  options: optionsSelector(state)
});

const FilterableSelect = connect(mapStateToProps)(props => (
  <Select {...props} />
));

ReactDOM.render(
  <Provider store={store}>
    <FilterableSelect />
  </Provider>,
  document.getElementById("root")
);

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:

Property Type Default Description
indexes Array<String> Optional array of attributes to build search index from; defaults to the labelKey attribute.
indexStrategy IndexStrategy AllSubstringsIndexStrategy See js-search docs
labelKey string "label" Option key containing the display text
options array [] Array of options objects
sanitizer Sanitizer LowerCaseSanitizer See js-search docs
searchIndex SearchIndex UnorderedSearchIndex See js-search docs
tokenizer Tokenizer SimpleTokenizer See js-search docs
valueKey string "value" Option key containing the value

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'

// Default index strategy is built for all substrings.
// In other word "c", "ca", "cat", "a", "at", and "t" all match "cat".
// Override to only allow exact-word matches like so:
const indexStrategy = new ExactWordIndexStrategy()

// Default sanitizer is case-insensitive
// Searches for "foo" will match "Foo".
// Override to be case-sensitive like so:
const sanitizer = new CaseSensitiveSanitizer()

// By default, search results are returned in the order they wre indexed.
// This means that your filtered options will match their unfiltered order.
// More advanced results orderings are possbile.
// For example TF-IDF ranking is an option.
// Learn more at https://github.com/bvaughn/js-search#tf-idf-ranking
const searchIndex = new TfIdfSearchIndex()

// Default tokenizer just splits search text on spaces.
// In other words "the boy" becomes 2 search tokens, "the" and "boy".
// The StemmingTokenizer can be used for fuzzier matching.
// For example, "searching" will match  "search", "searching", and "searched".
// Learn more at https://github.com/bvaughn/js-search#stemming
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.

More Repositories

1

react-virtualized

React components for efficiently rendering large lists and tabular data
JavaScript
25,929
star
2

react-window

React components for efficiently rendering large lists and tabular data
JavaScript
15,066
star
3

react-error-boundary

Simple reusable React error boundary component
TypeScript
6,179
star
4

react-resizable-panels

TypeScript
2,996
star
5

js-search

JS Search is an efficient, client-side search library for JavaScript and JSON objects
JavaScript
2,150
star
6

progress-estimator

Logs a progress bar and estimation for how long a Promise will take to complete
JavaScript
2,139
star
7

react-highlight-words

React component to highlight words within a larger body of text
JavaScript
2,102
star
8

redux-search

Redux bindings for client-side search
JavaScript
1,404
star
9

react-virtualized-select

HOC that uses react-virtualized and react-select to display large lists of options in a drop-down
JavaScript
1,164
star
10

react-devtools-experimental

Experimental rewrite of the React DevTools extension
966
star
11

react-window-infinite-loader

InfiniteLoader component inspired by react-virtualized but for use with react-window
JavaScript
860
star
12

react-virtualized-auto-sizer

Standalone version of the AutoSizer component from react-virtualized
TypeScript
566
star
13

planner

Lightweight, interactive planning tool that visualizes a series of tasks using an HTML canvas
JavaScript
537
star
14

react-presents

React slideshow framework
JavaScript
489
star
15

angular-form-for

Set of Angular directives to simplify creating and validating HTML forms.
JavaScript
428
star
16

js-worker-search

JavaScript client-side search API with web-worker support
JavaScript
410
star
17

react-flame-graph

React component for visualizing profiling data
JavaScript
385
star
18

suspense

Utilities for working with React Suspense
TypeScript
344
star
19

jest-react-profiler

Jest helpers for working with the React Profiler API.
JavaScript
279
star
20

highlight-words-core

Utility functions shared by react-highlight-words and react-native-highlight-words
JavaScript
222
star
21

redux-devtools-filterable-log-monitor

Filterable tree view monitor for Redux DevTools
JavaScript
155
star
22

personal-logger

Webapp for tracking personal diet, sleep, and general wellness
JavaScript
125
star
23

react-highlight.js

A simple React wrapper around the Highlight.js library
JavaScript
106
star
24

debounce-decorator

Decorator for debouncing class methods
JavaScript
93
star
25

use-context-menu

React components for displaying configurable context menus
TypeScript
90
star
26

forward-js-2017

Forward - Web Technology Summit
JavaScript
84
star
27

infinite-list-reflow-examples

Examples illustrating reflow handling with infinite lists
JavaScript
60
star
28

tweets

Twitter-like demo with limited functionality
JavaScript
56
star
29

react-devtools-tutorial

Interactive tutorial featuring the React DevTools v4
JavaScript
55
star
30

turdle

Wordle clone dedicated to 💩
JavaScript
55
star
31

jasmine-promise-matchers

Custom matchers for use with Jasmine 1.3 - 2.2 and Angular Promise objects.
JavaScript
51
star
32

babel-repl

React powered Babel REPL
JavaScript
42
star
33

extensions-api-proposal-custom-performance-pane

Extensions API proposal for the Performance Panel
36
star
34

task-runner

Async utilities for JavaScript application development with a focus on interruptibility and error-handling
JavaScript
34
star
35

react-window-table

JavaScript
34
star
36

immutable-js-store

Tiny observable wrapper around Immutable JS with rewind/replay support
JavaScript
34
star
37

live-stream-deep-dive-react-profiler

Source from live stream "Deep dive with the React DevTools profiler"
JavaScript
32
star
38

react-window-vs-react-virtualized-synced-grids

Comparison of react-virtualized MultiGrid to two react-window synced Grids
JavaScript
29
star
39

fps-measurer

Tiny testing utility for gathering FPS statistics
JavaScript
29
star
40

react-suspend-in-parallel

TypeScript
29
star
41

console.pretty

Pretty console logging
JavaScript
27
star
42

palettable

Generates an HTML color palette from SASS or Stylus source.
JavaScript
26
star
43

jasmine-es6-promise-matchers

ES6 Promise compatible Jasmine matchers
JavaScript
24
star
44

print-color

Utility for printing colored text in Node or the Browser
JavaScript
21
star
45

scheduling-profiler-prototype

Custom profiler prototype for React's concurrent mode
JavaScript
18
star
46

ng2-virtualized

Angular 2 components for efficiently rendering large, scrollable lists and tabular data
JavaScript
18
star
47

react-ascii-image

React component that displays image data as colored text
JavaScript
17
star
48

connect-tech-2016

Connect Tech 2016 presentation
JavaScript
14
star
49

react-wait-to-render

A function, component and mixin to defer component rendering until all required props are present
JavaScript
13
star
50

forms-js

Core forms-js library
JavaScript
12
star
51

faux-codesandbox-client

Example Code Sandbox and React DevTools v4 integration
JavaScript
11
star
52

react-conf-2018-profiling-keynote

2018 React Conf Profiling keynote
JavaScript
10
star
53

resume

HTML
10
star
54

react-resizable-panels-demo-ssr

TypeScript
9
star
55

bsky

Bluesky web UI (just for fun)
TypeScript
8
star
56

flat-object

Utilities for working with nested data structures
JavaScript
7
star
57

source-map-parsing-benchmark

JavaScript
6
star
58

react-immutable-js-store

React wrapper around immutable-js-store
JavaScript
6
star
59

test-extension-network-caching

JavaScript
6
star
60

react-devtools-triage-bot

GitHub bot for labeling and assigns bug reports for React DevTools that don't include repro info
JavaScript
5
star
61

jasmine-object-matchers

Custom object equality matchers for use with Jasmine 2.0.
JavaScript
5
star
62

react-createRoot-Suspense-async-act

JavaScript
4
star
63

test-github-issue-template

https://gh-community.github.io/issue-template-feedback/structured
3
star
64

test-named-hooks

Example create-react-app project meant to test React DevTools named hooks functionality
JavaScript
3
star
65

temp-devtools-profiler

Partial fork of React DevTools for testing Profiler plugin UI
JavaScript
3
star
66

TaskManager

Task Manager is an ActionScript library designed to simplify the implementation of asynchronous processes. This article is an introduction-to (and overview-of) the library.
3
star
67

bootstrap-select-button

Creates an Angular-friendly bindable button dropdown using the Bootstrap CSS framework
JavaScript
3
star
68

parcel-alpha-postcss-bug

JavaScript
2
star
69

test-github-actions

JavaScript
2
star
70

game-of-life

TypeScript
2
star
71

galaxiga-upgrade-tool

Web app to accompany Galaxiga mobile game
TypeScript
2
star
72

react-devtools-inline-node-and-web-poc

JavaScript
2
star
73

jqolor

JavaScript color picker built on top of jQuery and Bootstrap.
JavaScript
2
star
74

bvaughn

2
star
75

bug-repro-suspense-cache-read-extra-renders

JavaScript
1
star
76

briandavidvaughn

Angular website
HTML
1
star
77

react-suspense-transition-demo-app

Demo app
TypeScript
1
star
78

example-eslint-rule-override-issue

Repro
JavaScript
1
star
79

website

Personal website
TypeScript
1
star
80

SoundClouDownloader

Chrome extension enabling automatic downloads of any SoundCloud track, even when download option is disabled
JavaScript
1
star
81

gatsby-remark-prismjs-react-live-bug

Shows a bug between the 'gatsby-remark-prismjs' plugin and the 'react-live' library
CSS
1
star
82

transcluder

Another Angular directive to help with multiple transclusion within a single directive
JavaScript
1
star
83

jest-uncaught-error-repro

JavaScript
1
star
84

reflex-unit

Automatically exported from code.google.com/p/reflex-unit
HTML
1
star
85

TaskManagerCoffeeScript

CoffeeScript
1
star
86

.github

1
star