|
1 | | -import { ChangeEvent, FocusEvent } from 'react'; |
| 1 | +import { ChangeEvent, FocusEvent, useCallback } from 'react'; |
2 | 2 | import { |
3 | 3 | ariaDescribedByIds, |
4 | 4 | BaseInputTemplateProps, |
@@ -48,16 +48,30 @@ export default function BaseInputTemplate< |
48 | 48 | const inputProps = getInputProps<T, S, F>(schema, type, options, false); |
49 | 49 | const themeProps = cleanupOptions(options); |
50 | 50 |
|
51 | | - const handleNumberChange = (value: number | string) => onChange(value); |
| 51 | + const handleNumberChange = useCallback((value: number | string) => onChange(value), [onChange]); |
52 | 52 |
|
53 | | - const handleChange = onChangeOverride |
54 | | - ? onChangeOverride |
55 | | - : (e: ChangeEvent<HTMLInputElement>) => |
56 | | - onChange(e.target.value === '' ? (options.emptyValue ?? '') : e.target.value); |
| 53 | + const handleChange = useCallback( |
| 54 | + (e: ChangeEvent<HTMLInputElement>) => { |
| 55 | + const handler = onChangeOverride ? onChangeOverride : onChange; |
| 56 | + const value = e.target.value === '' ? (options.emptyValue ?? '') : e.target.value; |
| 57 | + handler(value); |
| 58 | + }, |
| 59 | + [onChange, onChangeOverride, options], |
| 60 | + ); |
57 | 61 |
|
58 | | - const handleBlur = (e: FocusEvent<HTMLInputElement>) => onBlur(id, e.target && e.target.value); |
| 62 | + const handleBlur = useCallback( |
| 63 | + (e: FocusEvent<HTMLInputElement>) => { |
| 64 | + onBlur(id, e.target && e.target.value); |
| 65 | + }, |
| 66 | + [onBlur, id], |
| 67 | + ); |
59 | 68 |
|
60 | | - const handleFocus = (e: FocusEvent<HTMLInputElement>) => onFocus(id, e.target && e.target.value); |
| 69 | + const handleFocus = useCallback( |
| 70 | + (e: FocusEvent<HTMLInputElement>) => { |
| 71 | + onFocus(id, e.target && e.target.value); |
| 72 | + }, |
| 73 | + [onFocus, id], |
| 74 | + ); |
61 | 75 |
|
62 | 76 | const input = |
63 | 77 | inputProps.type === 'number' || inputProps.type === 'integer' ? ( |
|
0 commit comments