react-select-cities

2.0.0 • Public • Published

React-Select-Cities

This package built on react-select to select cities, countries, regions, ..etc.

Installation and usage

NPM

You can install it using npm

npm install react-select-cities

then use it in your app like this:

import React, { useState } from 'react';
import ReactSelect from 'react-select-cities';

function App() {
  const [inputValue, setValue] = useState("");

  return (
    <div className="App">
        <ReactSelect
          maxCountriesNumber={5}
          onInputChange={value => {
            const inputValue = value.replace(/\W/g, "");
            setValue(inputValue);
            return inputValue;
          }}
          inputValue={inputValue}
          onChange={(a, b) => {
            console.log("from Parent: ", a, b);
          }}
        />
    </div>
  );
}

export default App;

Props

Prop Type Usage Note
maxCountriesNumber Number The maximum number of countries you can select. you can select any number of cities/regions/zipcode under those countries, but you can't add another country.
onInputChange Function fires when you change the input value. (inputValue) => { return inputValue;}
inputValue String The input value you entered you can manage it using state
onChange Function Fires when the value of cities changed (currentSelectedCities, lastAction) => {}

All the previous props are required and you have to set them.

Readme

Keywords

none

Package Sidebar

Install

npm i react-select-cities

Weekly Downloads

13

Version

2.0.0

License

none

Unpacked Size

150 kB

Total Files

6

Last publish

Collaborators

  • zeyadetman