/react-country-dropdown

A simple country selection react component

Primary LanguageJavaScriptMIT LicenseMIT

react-country-dropdown

A simple dropdown menu for selecting countries

npm

Screenshot from 2023-03-25 12-43-36

Install

npm install --save react-country-dropdown

Usage

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.)

License

MIT © RocktimSaikia