Skip to content

Commit 4a13faa

Browse files
committed
Memoize optionText
1 parent 86d6245 commit 4a13faa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/ra-ui-materialui/src/input/AutocompleteInput.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
warning,
3636
useGetRecordRepresentation,
3737
useEvent,
38+
OptionTextFunc,
3839
} from 'ra-core';
3940
import {
4041
SupportCreateSuggestionOptions,
@@ -163,7 +164,7 @@ export const AutocompleteInput = <
163164
onChange,
164165
onCreate,
165166
openText = 'ra.action.open',
166-
optionText,
167+
optionText: optionTextProp,
167168
optionValue,
168169
parse,
169170
resource: resourceProp,
@@ -228,6 +229,11 @@ export const AutocompleteInput = <
228229
...rest,
229230
});
230231

232+
// Memoize optionText
233+
const optionTextEvent = useEvent(optionTextProp as OptionTextFunc);
234+
const optionText =
235+
typeof optionTextProp === 'function' ? optionTextEvent : optionTextProp;
236+
231237
const finalChoices = useMemo(
232238
() =>
233239
// eslint-disable-next-line eqeqeq

0 commit comments

Comments
 (0)