Skip to content

jeyserver/react-phonenumber-select

Repository files navigation

react-phonenumber-select

Telephone number input React component. Made with jquery and select2.

NPM JavaScript Style Guide

React TypeScript jQuery

Install

npm i @jeyserver/react-phonenumber-select

Usage

import React, { useState } from 'react'
import ReactPhonenumber from '@jeyserver/react-phonenumber-select'

const countries = [
  { code: 'IR', name: 'Iran', dialingCode: '98' },
  { code: 'AF', name: 'Afghanistan', dialingCode: '93' },
  { code: 'AL', name: 'Albania', dialingCode: '213' },
  { code: 'AS', name: 'American Samoa', dialingCode: '1684' }
]

const App = () => {
  const [phoneNumber, setphoneNumber] = useState<string>('')

  const changePhoneNumber = (phoneNumber: string, selected:any) => {
    console.log(JSON.stringify({
      phoneNumber, selected
    }, null, 2))
  }

  return (
    <div>
      <ReactPhonenumber
        onChange={changePhoneNumber}
        countries={countries}
        defaultCode="IR"
      />
    </div>
  )
}

export default App