From 63e4654502961fabd627dc4f5ef2013b07926194 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Mon, 4 Aug 2025 10:41:09 +0400 Subject: [PATCH] fix: phone number input optimized --- src/components/PhoneInput/PhoneInput.tsx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/PhoneInput/PhoneInput.tsx b/src/components/PhoneInput/PhoneInput.tsx index 372c165..affbfe8 100644 --- a/src/components/PhoneInput/PhoneInput.tsx +++ b/src/components/PhoneInput/PhoneInput.tsx @@ -20,14 +20,13 @@ type AdditionalProps = { type InputProps = Omit< PolymorphicComponentProps, - "onChange" | "defaultValue" + "onChange" | "defaultValue" | "value" >; export type Props = AdditionalProps & InputProps; const PhoneInput = ({ initialCountryCode = "RU", - value: _value, onChange: _onChange, setPhoneMask: _setPhoneMask, ...props @@ -41,8 +40,6 @@ const PhoneInput = ({ const inputRef = useRef(null); const [dropdownWidth, setDropdownWidth] = useState(300); - const lastNotifiedValue = useRef(value ?? ""); - const onChange = (numberWithoutCode: string) => { setValue(numberWithoutCode); _onChange(`+${country.callingCode} ${numberWithoutCode}`); @@ -57,14 +54,6 @@ const PhoneInput = ({ setPhoneMask(initialData.current.format, country); }, [initialData.current.format]); - useEffect(() => { - const localValue = value.trim(); - if (localValue !== lastNotifiedValue.current) { - lastNotifiedValue.current = localValue; - onChange(localValue); - } - }, [country.code, value]); - const { readOnly, disabled } = props; const leftSectionWidth = 90; @@ -108,7 +97,7 @@ const PhoneInput = ({ inputMode={"numeric"} mask={mask} value={value} - onAccept={value => setValue(value)} + onAccept={onChange} /> ); };