Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-currency-input

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-currency-input

React component for inputing currency amounts

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
decreased by-32.22%
Maintainers
1
Weekly downloads
 
Created
Source

react-currency-input

An es6 react component for currency. Supports custom decimal and thousand separators as well as precision.

Installation

npm install react-currency-input --save

Integration

You can store the value passed in to the change handler in your state.

import React from 'react'
import CurrencyInput from 'react-currency-input';

const MyApp = React.createClass({
    getInitialState(){
        return ({amount: "0.00"});
    },
  
    handleChange(newValue){
        this.setState({amount: newValue});
    }
    render() {
        return (
            <div>
                <CurrencyInput value={this.state.amount} onChange={this.handleChange}/>
            </div>
        );
    }
}
export default MyApp

You can also assign a reference then access the value using a call to getMaskedValue()

import React from 'react'
import CurrencyInput from 'react-currency-input';

const MyApp = React.createClass({
    handleSubmit(event){
        event.preventDefault();
        console.log(this.refs.myinput.getMaskedValue())
    }
    render() {
        return (
            <form onSubmit={this.handleSubmit}>
                <CurrencyInput ref="myinput" />
            </form>
        );
    }
}
export default MyApp

Separators and Precision

Specify custom decimal and thousand separators:

    // 1.234.567,89
    <CurrencyInput decimalSeparator="," thousandSeparator="." />

Specify a specific precision:

    // 123,456.789
    <CurrencyInput precision="3" />
    // 123,456,789
    <CurrencyInput precision="0" />

Currency

Optionally set a currency symbol as a prefix or suffix

    // $1,234,567.89
    <CurrencyInput prefix="$" />
    // 1,234,567.89 kr
    <CurrencyInput suffix=" kr" />

Negative signs come before the prefix

    // -$20.00
    <CurrencyInput prefix="$" value="-20.00" />

All other attributes are applied to the input element. For example, you can integrate bootstrap styling:

    <CurrencyInput className="form-control" />

Options

OptionDefault ValueDescription
value0The initial currency value
onChangen/aCallback function to handle value changes
precision2Number of digits after the decimal separator
decimalSeparator'.'The decimal separator
thousandSeparator','The thousand separator
inputType"text"Input field tag type. You may want to use number or tel
allowNegativefalseAllows negative numbers in the input
prefix''Currency prefix
suffix''Currency suffix

Keywords

FAQs

Package last updated on 28 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc