Skip to main content
Version: <=v1.1.11

Phonecode Select

info

PhonecodeSelect is a simple and customizable phone code selector component for React applications. This component allows users to select a country phone code from a predefined list.

Usage

import React, { useState } from "react";
import { PhonecodeSelect } from "react-country-state-city";
import "react-country-state-city/dist/react-country-state-city.css";

export default function App() {
const [phonecode, setPhonecode] = useState(null);

return (
<div>
<h6>Phonecode</h6>
<PhonecodeSelect
containerClassName="form-group"
inputClassName=""
onChange={(_code) => setPhonecode(_code)}
onTextChange={(_txt) => console.log(_txt)}
defaultValue={phonecode}
placeHolder="Select Phone Code"
/>
</div>
);
}

Live Example

Props

NameTypeDefaultRequiredDescription
srcstringEmptyNoThe URL where the data files are hosted. Default is a CDN.
regionnumberEmptyNoFilters and displays countries from a specific region.
showFlagbooleantrueNoDisplays flags when true.
defaultValuestringnullNoThe initial selected phone code.
containerClassNamestringEmptyNoCustom class name for the container.
inputClassNamestringEmptyNoCustom class name for the input field.
onChangefunctionEmptyNoCallback triggered when a phone code is selected.
onTextChangefunctionEmptyNoCallback fired when the input text changes.
placeHolderstringEmptyNoPlaceholder text for the input.