An open API service indexing awesome lists of open source software.

https://github.com/imgarylai/use-tw-zipcode

這是一個用於處理台灣郵遞區號的 React Hook,提供以下功能 台灣縣市和鄉鎮市區的選擇 自動計算郵遞區號 提供完整的縣市和鄉鎮市區資料
https://github.com/imgarylai/use-tw-zipcode

hooks react reactjs taiwan typescript zipcode

Last synced: 4 months ago
JSON representation

這是一個用於處理台灣郵遞區號的 React Hook,提供以下功能 台灣縣市和鄉鎮市區的選擇 自動計算郵遞區號 提供完整的縣市和鄉鎮市區資料

Awesome Lists containing this project

README

          

# use-tw-zipcode

[![npm](https://img.shields.io/npm/v/use-tw-zipcode)](https://www.npmjs.com/package/use-tw-zipcode)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## Intro 簡介

可以簡單地製作台灣縣市、行政區下拉式選單,並取得郵遞區號。本套件只處理邏輯的部分,所以可以很簡單地應用於各種 CSS 版型。

Taiwanese zip code (3 digits) is determined by two factors: city and district. It is usually not necessary to ask users to fill in the zip code manually. It's more user-friendly if you can automatically capture the zip code once they select their city and district. A dropdown menu is commonly used for this scenario.

This library helps you create a user-friendly dropdown menu without any CSS/style framework dependency by using React hooks. You can find examples below. Let's build an excellent user interface together! 🙌🏻

## Installation 安裝

```bash
npm install use-tw-zipcode
```

## Example 範例

```jsx
import React from 'react';
import { useTwZipCode, cities, districts } from 'use-tw-zipcode';

export default function App() {
const { city, district, zipCode, handleCityChange, handleDistrictChange } = useTwZipCode();
return (



{city}
{district}
{zipCode}

handleCityChange(e.target.value)}>
{cities.map((city, i) => {
return {city};
})}

handleDistrictChange(e.target.value)}>
{districts[city].map((district, i) => {
return {district};
})}


);
}
```

## Live Demo

[https://use-tw-zipcode.vercel.app/](https://use-tw-zipcode.vercel.app/)

Demo Source Code: [https://github.com/imgarylai/use-tw-zipcode-vercel](https://github.com/imgarylai/use-tw-zipcode-vercel)