Skip to content

Commit

Permalink
Memoize stripDiacritics in filter for input
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Oct 24, 2019
1 parent 3750783 commit 3ca22b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/kind-yaks-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': patch
---

Memoize stripDiacritics in createFilter for the input with memoize-one so that stripDiacritics is not called for the same string as many times as there are options every time the input changes
5 changes: 4 additions & 1 deletion packages/react-select/src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type Config = {
};

import { stripDiacritics } from './diacritics';
import memoizeOne from 'memoize-one';

const memoizedStripDiacriticsForInput = memoizeOne(stripDiacritics);

const trimString = str => str.replace(/^\s+|\s+$/g, '');
const defaultStringify = option => `${option.label} ${option.value}`;
Expand All @@ -32,7 +35,7 @@ export const createFilter = (config: ?Config) => (
candidate = candidate.toLowerCase();
}
if (ignoreAccents) {
input = stripDiacritics(input);
input = memoizedStripDiacriticsForInput(input);
candidate = stripDiacritics(candidate);
}
return matchFrom === 'start'
Expand Down

0 comments on commit 3ca22b2

Please sign in to comment.