fix: phone number disappearing issue (#9811)

Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
pull/9476/head^2
Anmol Mahajan 2023-07-01 23:12:18 +05:30 committed by GitHub
parent 480bd48680
commit 2f85b8ad6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import { isSupportedCountry } from "libphonenumber-js";
import { useState } from "react";
import { useState, useEffect } from "react";
import PhoneInput from "react-phone-input-2";
import "react-phone-input-2/lib/style.css";
@ -18,11 +18,20 @@ export type PhoneInputProps = {
};
function BasePhoneInput({ name, className = "", onChange, ...rest }: PhoneInputProps) {
useEffect(() => {
if (!rest.value) {
return;
}
const formattedValue = rest.value.trim().replace(/^\+?/, "+");
onChange(formattedValue);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const defaultCountry = useDefaultCountry();
return (
<PhoneInput
{...rest}
country={defaultCountry}
country={rest.value ? undefined : defaultCountry}
enableSearch
disableSearchIcon
inputProps={{