MistaPidaus / react-use-country-region

A simple react hook to display a country regions

Home Page:https://mistapidaus.github.io/react-use-country-region/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-use-country-region

NPM JavaScript Style Guide

A simple react hook to display a country regions. Use with any UI Framework (Material UI) or any Headless UI (React Aria, Reach UI, etc) Uses country-region-data package dependencies to provide (latest) data.

Install

yarn add react-use-country-region

Usage

Get list of countries

To get list of available countries

import { useCountryRegion } from 'react-use-country-region';

const Example = () => {
  const { getCountryList } = useCountryRegion();
  const data = getCountryList();

  return <div>{JSON.stringify(data)}</div>;
};

Get list of regions

Simply pass a valid ISO country code to get regions/state/provice data

import { useCountryRegion } from 'react-use-country-region';

const Example = () => {
  const { result } = useCountryRegion('MY');
  return <div>{JSON.stringify(result.regions)}</div>;
};

License

MIT © MistaPidaus

About

A simple react hook to display a country regions

https://mistapidaus.github.io/react-use-country-region/


Languages

Language:TypeScript 64.0%Language:JavaScript 29.2%Language:HTML 5.9%Language:CSS 0.9%