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
countryidnumberEmptyThe id of the selected country object
srcstringEmptyURL where data files are hosted (e.g., https://venkatmcajj.github.io/react-country-state-city/)
defaultValueStatenullThe current value (a state object)
containerClassNamestringEmptyStyles for the container
inputClassNamestringEmptyStyles for the input box
onChangefunctionEmptyCallback with the selected state object as an argument
onTextChangefunctionEmptyCallback fired when the input text changes
placeHolderstringEmptyPlaceholder text displayed in an empty input