Skip to main content
Version: <=v1.1.11

State Select

info

The StateSelect component allows users to select a state based on the selected country. It supports customization through various props like defaultValue, onChange, and placeHolder.

Usage​

import React, { useState } from "react";
import { CountrySelect, StateSelect } 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);

return (
<div>
<h6>State</h6>
<StateSelect
countryid={country?.id}
containerClassName="form-group"
inputClassName=""
onChange={(_state) => setCurrentState(_state)}
onTextChange={(_txt) => console.log(_txt)}
defaultValue={currentState}
placeHolder="Select State"
/>
</div>
);
}

Live Example​

Country

State

Props​

NameTypeDefaultRequiredDescription
countryidnumberEmpty✅The id of the selected country object
srcstringEmpty❌URL where data files are hosted (e.g., https://venkatvidyut.github.io/react-country-state-city/)
defaultValueStatenull❌The current value (a state object)
containerClassNamestringEmpty❌Styles for the container
inputClassNamestringEmpty❌Styles for the input box
onChangefunctionEmpty❌Callback with the selected state object as an argument
onTextChangefunctionEmpty❌Callback fired when the input text changes
placeHolderstringEmpty❌Placeholder text displayed in an empty input