Socket
Socket
Sign inDemoInstall

use-react-countries

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-react-countries

A tiny fully customizable react hook which gives you full list of countries with their flags, emojis and descriptions


Version published
Weekly downloads
819
decreased by-35.15%
Maintainers
1
Install size
1.91 MB
Created
Weekly downloads
 

Readme

Source

use-react-countries

A tiny fully customizable react hook which gives you full list of countries with their flags, emojis, country calling codes, postal codes and many more...

NPM JavaScript Style Guide

Install

  • npm
npm install --save use-react-countries
  • yarn
yarn add use-react-countries

Examples

See this codesandbox playground or /example folder if you want to play with hook.

Usage

A simple example of a component which you can copy-paste and take info about all countries.

import { useCountries } from 'use-react-countries'

const Example = () => {
  const { countries } = useCountries()

  return (
    <div>
      {countries.map(
        ({
          name,
          postalCode,
          emoji,
          capital,
          area,
          population,
          countryCallingCode
        }) => (
          <section>
            <h2>
              {emoji} {name}
            </h2>
            <p>
              Post code: {postalCode?.format} <br /> Regex for post code:{' '}
              {postalCode?.regex}
            </p>
            <p>{capital}</p>
            <p>{area}</p>
            <p>{population}</p>
            <p>{countryCallingCode}</p>
          </section>
        )
      )}
    </div>
  )
}

API

  • Country interface
type country = {
  name: string,
  capital: string,
  area: number,
  coordinates: number[],
  currencies: {
    name: string,
    symbol: string
  }[],
  languages: string[],
  maps: {
    googleMaps: string,
    openStreetMaps: string
  },
  postalCode: {
    format: string,
    regex: string
  },
  flags: {
    png: string,
    svg: string
  },
  population: number,
  emoji: string,
  countryCallingCode: string
}
PropertyTypeDescription
namestring
capitalstring
areanumber
emojistring
flags{ png: string, svg: string }
countryCallingCodenumber
populationnumber
currencies{ name: string, symbol: string }[]
languagesstring[]
maps{ googleMaps: string, openStreetMaps: string }
postalCode{ format: string, regex: string }
coordinates[number, number]

Authors

License

MIT © vre2h


This hook is created using create-react-hook.

FAQs

Last updated on 14 Apr 2024

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