Skip to content

Commit

Permalink
types for initialValue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiHotz committed Aug 26, 2023
1 parent a18e456 commit 613c2f4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-phonenr-input",
"version": "3.2.4",
"version": "3.2.5",
"description": "An automated and intuitive international and national phone input field",
"author": "Kai Hotz",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePhonenumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const usePhonenumber = ({ initialValue, initialCountry, format }: IUsePho
phoneNumber: isInternational && initialCountry ? initialCountry.dialCode : '',
};

if (initialValue) {
if (initialValue && typeof initialValue === 'string') {
const metaData = findPhoneNumbersInText(initialValue);
const selectedCountry = findCountryByCode(metaData[0].number.country);
const formated = selectedCountry ? formatNumber(initialValue, format, selectedCountry.iso2) : initialValue;
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface IPhoneInputProps extends Omit<InputHTMLAttributes<HTMLInputElem
*/
withCountryMeta?: boolean;
/** Sets the initial Value of the Phonenumber Input. This is usefull in case you need to set a phonenumber stored for example in a database */
initialValue?: string;
initialValue?: PhoneNumber;
/** Sets the default country (use iso alpha-2 country code e.g 'US', 'GB', 'DE') */
defaultCountry?: CountryCode;
/** Lets you restrict the country dropdown to a specific list of countries (use iso alpha-2 country code e.g 'US', 'GB', 'DE') */
Expand All @@ -71,5 +71,5 @@ export interface IPhoneNumberState {
export interface IUsePhoneInputProps {
format: NumberFormat;
initialCountry?: ICountry;
initialValue?: string;
initialValue?: PhoneNumber;
}

0 comments on commit 613c2f4

Please sign in to comment.