Socket
Socket
Sign inDemoInstall

react-multiple-selector

Package Overview
Dependencies
78
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-multiple-selector

This package built on [`react-select`](https://www.npmjs.com/package/react-select) to select cities, countries, regions, ..etc.


Version published
Weekly downloads
3
decreased by-89.29%
Maintainers
2
Install size
12.8 MB
Created
Weekly downloads
 

Readme

Source

react-multiple-selector

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-multiple-selector

then use it in your app like this:

import React, { useState } from 'react';
import ReactSelect from 'react-multiple-selector';

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

  function onChange(value, callback) {
    if(!value) return callback([]);
    return new Promise((resolve, reject) => {
      const url = `https://api.test.com`;
      return fetch(url).then(async response => {
        if (response.ok) {
          const data = await response.json();
          const modifiedData = data.map(i => ({key: i._id, ...i}));
          callback(modifiedData);
        } else {
          reject(new Error('error'))
        }
      }, error => {
        reject(new Error(error.message))
      })
    })
  }

  return (
    <div className="App">
        <ReactSelect
          maxSelectedItems={5}
          onInputChange={(e) => {
            setValue(e);
            return e;
          }}
          debounceTime={2000}
          loadOptions={onChange}
          inputValue={inputValue}
          onChange={(a, b) => {
            console.log("from Parent: ", a, b);
          }}
          customType="Country"
        />
    </div>
  );
}

export default App;

Props

PropTypeUsageNote
maxSelectedItemsNumberThe 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.
onInputChangeFunctionfires when you change the input value.(inputValue) => { return inputValue;}
inputValueStringThe input value you enteredyou can manage it using state
onChangeFunctionFires when the value of cities changed(currentSelectedCities, lastAction) => {}
loadOptionsFunctionFires to load options to select(value, callback) => ...
labelOptionStringLabel Option to show in options list or when selecteddefault = 'name'
valueOptionStringUnique value option to selectdefault = '_id'
typeOptionStringProperty to set maximum selected items on itdefault = 'type'
customTypeStringPrevious Property value to apply the maximum on itdefault = 'country'
debounceTimeNumberDebounce time applied to onChange function so the function doesn't fire before your last keyboard click and this timedefault = 300
valueArrayList of default values[{}, {}, ...]
placeholderStringPlaceholder for searchingdefault = 'Search...'

FAQs

Last updated on 16 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc