A simple dropdown menu for selecting countries
npm install --save react-country-dropdown
import React, { Component } from 'react'
import { ReactCountryDropdown } from 'react-country-dropdown'
import 'react-country-dropdown/dist/index.css'
const Example = () => {
const handleSelect = (country) => {
console.log(country)
/* returns the details on selected country as an object
{
name: "United States of America",
code: "US",
capital: "Washington, D.C.",
region: "Americas",
latlng: [38, -97]
}
*/
}
return (
<div>
<ReactCountryDropdown onSelect={handleSelect} countryCode='IN' />
</div>
)
}
(If you dont select set a default country with "countryCode" ; Then by default the selected country will US.)
MIT © RocktimSaikia