Skip to main content
Version: <=v1.1.11

City Select

info

The CitySelect component allows users to select a city based on a selected country and state. It provides a simple and flexible interface for integrating city selection in your React applications.

Usage

import React, { useState } from "react";
import { CountrySelect, StateSelect, CitySelect } 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);
const [currentState, setCurrentState] = useState(null);
const [currentCity, setCurrentCity] = useState(null);

return (
<div>
{/* Country Selection */}
...

{/* State Selection */}
...

{/* City Selection */}
<h6>City</h6>
<CitySelect
countryid={country?.id}
stateid={currentState?.id}
onChange={(_city) => setCurrentCity(_city)}
defaultValue={currentCity}
placeHolder="Select City"
/>
</div>
);
}

Live Example

Country
State
City

Props

Prop NameTypeDefaultRequiredDescription
countryidnumberEmptyThe ID of the selected country.
stateidnumberEmptyThe ID of the selected state.
srcstringEmptyURL to host data files. Defaults to a hosted CDN.
defaultValueCitynullThe initial selected city object.
containerClassNamestringEmptyCSS class for the container.
inputClassNamestringEmptyCSS class for the input field.
onChange(city: City) => voidEmptyCallback triggered when a city is selected.
onTextChange(text: string) => voidEmptyCallback triggered when input text changes.
placeHolderstringEmptyPlaceholder text for the input field.