Skip to main content
Version: Latest

Country Select

info

CountrySelect is a React component that provides an easy-to-use dropdown for selecting countries. It supports customizable styling, region-based filtering, and event handlers for value changes, making it ideal for forms and location-based inputs.


Usage

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

export default function App() {
const [country, setCountry] = useState(null);

return (
<div>
<h6>Country</h6>
<CountrySelect
containerClassName="form-group"
inputClassName=""
onChange={(_country) => setCountry(_country)}
onTextChange={(_txt) => console.log(_txt)}
placeHolder="Select Country"
/>
</div>
);
}

Live Example

Country

Props

Prop NameTypeDefaultRequiredDescription
srcstringEmptyThe relative or absolute URL where the data files are hosted. Default is to serve from a hosted CDN, e.g., https://venkatmcajj.github.io/react-country-state-city/.
regionnumberEmptyFilters and displays only the countries that belong to a specific region.
defaultValueCountry | string (name) | number (id)nullThe current value: a country object or country name or country id.
containerClassNamestringEmptyStyles for a container.
inputClassNamestringEmptyStyles for an input box.
onChangefunctionEmptyThe current value: a country object. The argument is the country object.
onTextChangefunctionEmptyA callback fired when the input text changes.
placeHolderstringEmptyPlaceholder text displayed in an empty input.
showFlagbooleantrueFlags are displayed when true and hidden when false.