|
1 |
| -import React, { ChangeEvent, FocusEvent } from "react"; |
| 1 | +import React, { ChangeEvent, FocusEvent, useCallback } from "react"; |
2 | 2 | import { processSelectValue, WidgetProps } from "@rjsf/utils";
|
3 | 3 |
|
4 | 4 | function getValue(
|
@@ -37,20 +37,29 @@ function SelectWidget<T = any, F = any>({
|
37 | 37 | const { enumOptions, enumDisabled } = options;
|
38 | 38 | const emptyValue = multiple ? [] : "";
|
39 | 39 |
|
40 |
| - const handleFocus = (event: FocusEvent<HTMLSelectElement>) => { |
41 |
| - const newValue = getValue(event, multiple); |
42 |
| - return onFocus(id, processSelectValue(schema, newValue, options)); |
43 |
| - }; |
| 40 | + const handleFocus = useCallback( |
| 41 | + (event: FocusEvent<HTMLSelectElement>) => { |
| 42 | + const newValue = getValue(event, multiple); |
| 43 | + return onFocus(id, processSelectValue(schema, newValue, options)); |
| 44 | + }, |
| 45 | + [onFocus, id, schema, multiple, options] |
| 46 | + ); |
44 | 47 |
|
45 |
| - const handleBlur = (event: FocusEvent<HTMLSelectElement>) => { |
46 |
| - const newValue = getValue(event, multiple); |
47 |
| - return onBlur(id, processSelectValue(schema, newValue, options)); |
48 |
| - }; |
| 48 | + const handleBlur = useCallback( |
| 49 | + (event: FocusEvent<HTMLSelectElement>) => { |
| 50 | + const newValue = getValue(event, multiple); |
| 51 | + return onBlur(id, processSelectValue(schema, newValue, options)); |
| 52 | + }, |
| 53 | + [onBlur, id, schema, multiple, options] |
| 54 | + ); |
49 | 55 |
|
50 |
| - const handleChange = (event: ChangeEvent<HTMLSelectElement>) => { |
51 |
| - const newValue = getValue(event, multiple); |
52 |
| - return onChange(processSelectValue(schema, newValue, options)); |
53 |
| - }; |
| 56 | + const handleChange = useCallback( |
| 57 | + (event: ChangeEvent<HTMLSelectElement>) => { |
| 58 | + const newValue = getValue(event, multiple); |
| 59 | + return onChange(processSelectValue(schema, newValue, options)); |
| 60 | + }, |
| 61 | + [onChange, schema, multiple, options] |
| 62 | + ); |
54 | 63 |
|
55 | 64 | return (
|
56 | 65 | <select
|
|
0 commit comments