react-number-format is a React component library designed for formatting numeric and pattern-based input fields, as well as displaying formatted text. It provides functionalities for adding prefixes, suffixes, and thousands separators, alongside comprehensive input masking capabilities for various patterns like credit card numbers or phone numbers. The library is currently stable at version 5.4.5 and is actively maintained with frequent bug fix releases, supporting a wide range of React versions up to 19. Its key differentiators include a sophisticated caret engine that handles complex formatting scenarios, custom pattern formatting, and the ability to define custom formatting handlers, offering a high degree of customization for user input experiences. The project emphasizes robust handling of user input while ensuring display consistency.
npm install react-number-formatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `NumericFormat` for currency input with thousands separators and decimal precision, and `PatternFormat` for a phone number mask, showing how to manage their values with React state.
Consult the official v4 to v5 migration guide at `https://s-yadav.github.io/react-number-format/docs/migration` and update your component props and imports accordingly.
Remove any direct usage of the `isCharacterSame` prop from `NumericFormat` and `PatternFormat` components. If similar functionality is needed for custom solutions, explore `NumberFormatBase` or alternative approaches.
Ensure you are on the latest patch version of `react-number-format`. If issues persist, test with simplified configurations and consider opening an issue on the GitHub repository with a minimal reproduction.
For versions prior to v5.3.1, this could be related to `valueIsNumericString` not being provided when `values.value` is used. Ensure your `onValueChange` callback manages state correctly without causing infinite loops. Check for strict equality in dependency arrays for `useEffect` if used.
Change `const { Name } = require('react-number-format');` to `import { Name } from 'react-number-format';`.Upgrade to `react-number-format` version `5.4.5` or newer. If you need to programmatically set the initial value and ensure `onValueChange` fires, use the `value` prop with `useState` and manually set the initial state.