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.
npm install react-international-phoneVerified import paths — ran on the pinned version, not inferred.
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.
Refer to the official migration guide 'Update from v3 to v4' at `https://react-international-phone-docs.vercel.app/docs/Migrations/migrate-to-v4` for detailed instructions and code examples to adapt to the new API.
Consult the 'Update from v2 to v3' migration guide at `https://react-international-phone-docs.vercel.app/docs/Migrations/migrate-to-v3` to understand specific changes and how to update your codebase.
Review the 'Update from v1 to v2' migration guide available at `https://react-international-phone-docs.vercel.app/docs/Migrations/migrate-to-v2` to understand the necessary modifications for a successful upgrade.
Ensure you include `import 'react-international-phone/style.css';` in your entry file or the component file where `PhoneInput` is used.
Carefully read the `usePhoneInput` documentation to understand all returned properties and methods, and manually bind them to your custom input and selector elements. Do not expect any default UI.
Change your import statement to `import { PhoneInput } from 'react-international-phone';`Ensure `react-international-phone/style.css` is imported and that no custom build steps are interfering with module resolution. If in SSR, check the library's SSR compatibility documentation.
Ensure `value` is a string (the full international number) and `onChange` accepts a string parameter, matching the `PhoneInput` component's type definitions. For example: `onChange={(phone: string) => setPhone(phone)}`.