react-continent-country-select
LIVE DEMO: https://mjakal.github.io/react-continent-country-select/
Requirements
- bootstrap >= 4.0.0
- flag-icon-css >= 3.0.0 - if you want to display country flags (not required)
- font-awesome >= 4.7.0 - used for toggle button icon (not required)
- react >= 16.8.0
- react-dom >= 16.8.0
- reactstrap >= 8.0.0
Install
npm install --save react-continent-country-select
Usage
import React useState from 'react';import ContinentCountrySelect deserializeCountries serializeCountries from 'react-continent-country-select';import 'react-continent-country-select/dist/index.css';import continents from 'react-continent-country-select/dist/continent_countries.json'; // pre-selected values from e.g. API endpointconst countries = 'be' 'nl' 'hr';// Deserialize data: convert ['be', 'nl', 'hr'] to { BE: true, NL: true, HR: true }const deserializedCountries = ; const App = const selectedCountries setSelectedCountries = ; // You can create custom country component const CountryComponent = country const code = countrycode; const label = ` (+)`; return <span> <i = = /> label </span> ; ; const onChange = ; const onSerializeData = // Serialize selected countries // The second boolean param is used for serializing data depending on your specific needs (upper/lower case) const serializedCountries = ; ; ; return <div> <ContinentCountrySelect = // = // = // - = // = // = // /> <button ="button" => Serialize Selected Countries </button> </div> ;; ;