React Currency Input Field

4.0.5 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import React, { useState } from 'react';
import CurrencyInput from 'react-currency-input-field';

const MyCurrencyForm = () => {
  const [value, setValue] = useState<string | undefined>('1234.56');

  return (
    <div>
      <label htmlFor="currency-input">Enter Amount:</label>
      <CurrencyInput
        id="currency-input"
        name="currency-field"
        placeholder="Please enter an amount"
        defaultValue={1234.56}
        decimalsLimit={2}
        prefix="$"
        onValueChange={(value, name, values) => {
          setValue(value);
          console.log(`Value: ${value}, Name: ${name}, Values:`, values);
        }}
        value={value} // Use value for controlled component behavior
      />
      <p>Current Input: {value}</p>
    </div>
  );
};

export default MyCurrencyForm;

view raw JSON →