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
countryidnumberEmpty✅The ID of the selected country.
stateidnumberEmpty✅The ID of the selected state.
srcstringEmpty❌URL to host data files. Defaults to a hosted CDN.
defaultValueCitynull❌The initial selected city object.
containerClassNamestringEmpty❌CSS class for the container.
inputClassNamestringEmpty❌CSS class for the input field.
onChange(city: City) => voidEmpty❌Callback triggered when a city is selected.
onTextChange(text: string) => voidEmpty❌Callback triggered when input text changes.
placeHolderstringEmpty❌Placeholder text for the input field.