Skip to content

Commit 3ca22b2

Browse files
committed
Memoize stripDiacritics in filter for input
1 parent 3750783 commit 3ca22b2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/kind-yaks-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-select': patch
3+
---
4+
5+
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

packages/react-select/src/filters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ type Config = {
99
};
1010

1111
import { stripDiacritics } from './diacritics';
12+
import memoizeOne from 'memoize-one';
13+
14+
const memoizedStripDiacriticsForInput = memoizeOne(stripDiacritics);
1215

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

0 commit comments

Comments
 (0)