Telephone number input React component. Made with jquery and select2.
npm i @jeyserver/react-phonenumber-select
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