1.2.0 • Published 1 year ago

react-postal-code v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

React Postal Code

React Postal Code is a library that can be used inside any ReactJS app. This library can be used to render Country, District & Block/City for any given Indian Pin Code. This library uses the official REST API provided by the Indian Government.

Working

import { Pin } from 'react-postal-code'

JS

import React, { useState } from 'react';
import { Pin } from 'react-postal-code'

function App() {
  const [input, setInput] = useState<string>('');
  return (
    <>
        <input type="search" onChange={(e) => setInput(e.target.value)}>
        <Pin
            pincode={input}
            showBlock={true}
            showCountry={true}
            showDistrict={true}
            // lengthValidation="Optional custom length error message"
            // errorState="Optional custom error state for no data or data error"
        />
    </>
  );
}

Playground

Codesandbox Implementation of this Library here

Pin Props

  1. Props for changing CSS Styles
NameDescriptionRequired
_containerContainer which wraps all 3 divsOptional
_validationClass name for Length CheckOptional
_error_stateClass Name for Error CheckOptional
_districtClass Name for District divOptional
_blockClass Name for block divOptional
_countryClass Name for Country divOptional
  1. Props for changing error states.

By default,

  • For a Pin code less than 6 digits - "Error - Enter 6 digits"
  • If a Pin code is not found/data error - "Error - No Data found"
NameDescriptionRequired
lengthValidationProps for changing invalid length stateOptional
errorStateProps for changing data error stateOptional
  1. Pin component props.

By default,

  • showCountry - false
  • showDistrict - false
  • showBlock - false Turn them to true to render out these data
NameDescriptionRequired
pincodeProps for changing Pin CodeRequired
showCountryProps for rendering Country NameOptional
showDistrictProps for rendering District NameOptional
showBlockProps for rendering Block/City NameOptional

Note

This will only work for Indian Postal/Pin Codes. Provide true to one of showCountry/showDistrict/showBlock props

Owner

Abhinav