country-react-select
v1.0.1
Published
React select component for Country, State, City databases. It supports country, state and city dropdown in Reactjs.
Downloads
8
Maintainers
Readme
Country-react-select
The Country State Select control for React.
Features include:
- Country picker.
- State picker.
- City picker.
Installation and usage
yarn add country-react-select
or
npm instal country-react-select --save
Sample code
Country picker:
import React, { useState } from 'react';
import {CountryPicker} from 'country-react-select';
export default function App() {
const [selectedOption, setSelectedOption] = useState(null);
return (
<div className="App">
<CountryPicker
value={selectedOption}
onChange={setSelectedOption}
/>
</div>
);
}
CountryPickerProps
isDisabled
- disable the controlisMulti
- allow the user to select multiple valuesonChange
- subscribe to change eventsplaceholder
- change the text displayed when no option is selectedvalue
- control the current value
State picker:
import React, { useState } from 'react';
import {StatePicker} from 'country-react-select';
export default function App() {
const [selectedOption, setSelectedOption] = useState(null);
return (
<div className="App">
<StatePicker
value={selectedOption}
onChange={setSelectedOption}
country={'CA'}
/>
</div>
);
}
City picker:
import React, { useState } from 'react';
import {CityPicker} from 'country-react-select';
export default function App() {
const [selectedOption, setSelectedOption] = useState(null);
return (
<div className="App">
<CityPicker
value={selectedOption}
onChange={setSelectedOption}
country={'CA'}
state={'QC'}
/>
</div>
);
}
License
MIT Licensed. Copyright (c) Vu Vo 2023.