Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-hook-currency
Advanced tools
Readme
This libraries propose to introduce two pseudo hooks, one capable of format currencies and another capable to simulate a cash register.
npm install react-hook-currency # or yarn add react-hook-currency
Chrome | Edge | Firefox | Safari | IE 11 |
---|---|---|---|---|
:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
import React from 'react';
import { useCurrency } from 'react-hook-currency';
const ControlledInputCurrency = () => {
const { onClick, onChange, onKeyDown, format, toNumber } = React.useMemo(
() => useCurrency(),
[]
);
const [value, setValue] = React.useState(format('000'));
return (
<input
type="text"
onChange={e => {
onChange(e);
console.log(toNumber(e.target.value)); // Number
setValue(e.target.value);
}}
onKeyDown={onKeyDown}
onClick={onClick}
value={value}
/>
);
};
const UncontrolledInputCurrency = () => {
const { onClick, onChange, onKeyDown, format } = React.useMemo(
() => useCurrency(),
[]
);
const ref = React.useRef<HTMLInputElement>(null);
return (
<input
type="text"
onChange={onChange}
onKeyDown={onKeyDown}
onClick={onClick}
defaultValue={format('000')}
ref={ref}
/>
);
};
import React from 'react';
import { useCurrencyRegister } from 'react-hook-currency';
const UncontrolledInputCashRegister = () => {
const { onClick, onChange, onKeyDown, format } = useCurrencyRegister();
const ref = React.useRef<HTMLInputElement>(null);
return (
<input
type="text"
onClick={onClick}
onChange={onChange}
onKeyDown={onKeyDown}
defaultValue={format('000')}
autoFocus={true}
ref={ref}
/>
);
};
Props | Default Value | Description |
---|---|---|
precision | 2 | Fraction Digits |
style | currency | currency or decimal(Remove symbol) |
locale | pt-BR | Country Code Reference(Currency symbol) |
currency | BRL | String i18n(Format Type) |
negative * | allow | allow, always, never |
Note: *not present in useCurrencyRegister
Return | Type |
---|---|
onClick | Function => void |
onChange | Function => void |
onKeyDown | Function => void |
format | Function => void |
decimalSeparator | string |
toNumber | Function => number |
triggerChange * | Function => void |
Note: *not present in useCurrency
Fell free to contribute. Create a branch, add commits, and open a pull request.
FAQs
> This libraries propose to introduce two pseudo hooks, one capable of format currencies and another capable to simulate a cash register.
The npm package react-hook-currency receives a total of 120 weekly downloads. As such, react-hook-currency popularity was classified as not popular.
We found that react-hook-currency demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.