React International Phone Input

4.8.0 · active · verified Sun Apr 19

React International Phone is a lightweight and easy-to-integrate React component for handling international phone number inputs. It's currently at stable version 4.8.0, with frequent minor and patch releases to update country data, fix bugs, and add small features. Key differentiators include its small bundle size with no third-party runtime dependencies, automatic country guessing based on input, comprehensive validation utilities, and flexible customization options. It also provides a headless hook (`usePhoneInput`) for integrating with any UI library, allowing developers to maintain consistent styling while leveraging the library's core functionality for phone number formatting and country detection. It ships with TypeScript types for enhanced developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic international phone input component, initializes it with a default country, and updates the state on change. It also shows how to include the necessary styles and add basic input props.

import { useState } from 'react';
import { PhoneInput } from 'react-international-phone';
import 'react-international-phone/style.css';

const App = () => {
  const [phone, setPhone] = useState('');

  return (
    <div style={{
      display: 'flex',
      flexDirection: 'column',
      alignItems: 'center',
      justifyContent: 'center',
      minHeight: '100vh',
      fontFamily: 'sans-serif'
    }}>
      <h1>Phone Number Input</h1>
      <PhoneInput
        defaultCountry="us"
        value={phone}
        onChange={(phone) => setPhone(phone)}
        inputProps={{
          name: 'phone',
          placeholder: 'Enter phone number',
          autoComplete: 'tel'
        }}
        className="my-custom-phone-input"
      />
      <p style={{ marginTop: '20px' }}>Current Phone: {phone || 'None'}</p>
    </div>
  );
};

export default App;

view raw JSON →