React Currency Input Field is a lightweight and feature-rich React component designed for formatting currency and numerical inputs within forms. Currently stable at version 4.0.5, it receives moderate updates, primarily focused on build stability and compatibility, as evidenced by recent patch releases. Key differentiators include support for numerical abbreviations (e.g., '1k'), customizable prefixes and suffixes, automatic group separators, and integration with the Internationalization API (Intl locale config) for region-specific formatting. It also provides keyboard stepping, allows/disallows decimals and negative values, and ships with full TypeScript support, all while maintaining zero runtime dependencies (beyond React itself) and a minimal bundle size.
npm install react-currency-input-fieldVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a controlled currency input field using React's `useState` hook, setting an initial value, a prefix, and handling value changes.
Review your bundler configuration (e.g., Webpack, Rollup) for potential conflicts with esbuild's output. Ensure your project's module resolution settings are compatible with modern ESM/CJS outputs.
Upgrade to `react-currency-input-field@4.0.3` or newer. This version specifically includes fixes to bundle ESM/CJS builds to address Node ESM resolution issues in SSR.
For controlled components, always bind the `value` prop to state and update it via the `onValueChange` handler. For uncontrolled components, use `defaultValue` for initial state and avoid providing `value` prop unless explicitly making it controlled.
When using CommonJS `require`, destructure the default export: `const { default: CurrencyInput } = require('react-currency-input-field');` or migrate to ES modules: `import CurrencyInput from 'react-currency-input-field';`Ensure the package is installed: `npm install react-currency-input-field` or `yarn add react-currency-input-field`. Verify your bundler's module resolution paths and aliases. For SSR, ensure you are on `v4.0.3` or newer for better ESM/CJS compatibility.
Choose either `defaultValue` (uncontrolled) or `value` (controlled with `onValueChange`) for the entire lifecycle of the component. If `value` is used, ensure it is always defined or explicitly `null` if no value is present, rather than switching between `undefined` and defined.