2.0.4 • Published 2 years ago

use-tw-zipcode v2.0.4

Weekly downloads
57
License
MIT
Repository
github
Last release
2 years ago

use-tw-zipcode

npm semantic-release

Intro 簡介

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

Taiwanese zip code, 3 digits style, is determined by two factors, city and district. It is usually not necessary to ask users to fill the zip code by themselves. It is nicer if you are building an interface capturing zip code automatically once they fill in the field, city, and district. And a dropdown menu is commonly used for this scenario.

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

Installation 安裝

npm install use-tw-zipcode

Example 範例

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

export default function App() {
  const { city, district, zipCode, handleCityChange, handleDistrictChange } = useTwZipCode();
  return (
    <div>
      <div>
        {city}
        {district}
        {zipCode}
      </div>
      <select onChange={(e) => handleCityChange(e.target.value)}>
        {cities.map((city, i) => {
          return <option key={i}>{city}</option>;
        })}
      </select>
      <select onChange={(e) => handleDistrictChange(e.target.value)}>
        {districts[city].map((district, i) => {
          return <option key={i}>{district}</option>;
        })}
      </select>
    </div>
  );
}

Other examples 其他範例

MATERIAL-UI 一起使用

This example shows how to work with CSS framework. In this example, it comes with MATERIAL-UI.

Edit use-tw-zipcode

Live Demo

https://use-tw-zipcode.now.sh/

2.0.4

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago