diff --git a/.changeset/kind-yaks-clean.md b/.changeset/kind-yaks-clean.md new file mode 100644 index 0000000000..63316e7532 --- /dev/null +++ b/.changeset/kind-yaks-clean.md @@ -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 diff --git a/packages/react-select/src/filters.js b/packages/react-select/src/filters.js index 3dea2f2a7d..3f738f90ef 100644 --- a/packages/react-select/src/filters.js +++ b/packages/react-select/src/filters.js @@ -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}`; @@ -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'