Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
react-currency-input
Advanced tools
An es6 react component for currency. Supports custom decimal and thousand separators as well as precision.
npm install react-currency-input --save
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({
handleChange(newValue){
console.log(newValue)
}
render() {
return (
<div>
<CurrencyInput value="0" 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 value="0" ref="myinput" />
</form>
);
}
}
export default MyApp
Specify custom decimal and thousand separators:
// 1.234.567,89
<CurrencyInput decimalSeparator="," thousandSeparator="." value="0" onChange={this.handleChange} />
Specify a specific precision:
// 123,456.789
<CurrencyInput precision="3" value="0" onChange={this.handleChange} />
// 123,456,789
<CurrencyInput precision="0" value="0" onChange={this.handleChange} />
All other attributes are applied to the input element. For example, you can integrate bootstrap styling:
<CurrencyInput className="form-control" value="0" onChange={this.handleChange} />
Option | Default Value | Description |
---|---|---|
value | 0 | The initial currency value |
onChange | n/a | Callback function to handle value changes |
precision | 2 | Number of digits after the decimal separator |
decimalSeparator | '.' | The decimal separator |
thousandSeparator | ',' | The thousand separator |
FAQs
React component for inputing currency amounts
The npm package react-currency-input receives a total of 4,002 weekly downloads. As such, react-currency-input popularity was classified as popular.
We found that react-currency-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.