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.
yarn add react-use-country-region
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>;
};
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>;
};
MIT © MistaPidaus