https://github.com/cool-hooks/react-currency-hooks
💰 Currency converter React hook
https://github.com/cool-hooks/react-currency-hooks
converter currency hooks library money react
Last synced: about 2 months ago
JSON representation
💰 Currency converter React hook
- Host: GitHub
- URL: https://github.com/cool-hooks/react-currency-hooks
- Owner: cool-hooks
- License: mit
- Created: 2019-12-19T19:24:59.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T04:33:04.000Z (over 3 years ago)
- Last Synced: 2025-09-18T08:59:28.487Z (10 months ago)
- Topics: converter, currency, hooks, library, money, react
- Language: TypeScript
- Homepage:
- Size: 1.12 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# [react-currency-hooks](https://github.com/cool-hooks/react-currency-hooks)
[](https://www.npmjs.com/package/react-currency-hooks)
[](https://www.npmjs.com/package/react-currency-hooks)
[](https://www.npmjs.com/package/react-currency-hooks)
[](https://codecov.io/gh/cool-hooks/react-currency-hooks)
[](https://travis-ci.org/cool-hooks/react-currency-hooks)
[](https://bundlephobia.com/result?p=react-currency-hooks)
## About
Currency converter React hook
### Demo
**[Playground – play with the library in CodeSandbox](https://codesandbox.io/s/react-currency-hooks-l3b1l)**
### Similar Projects
- [Cashify](https://github.com/xxczaki/cashify/) by [Antoni Kepinski](https://github.com/xxczaki/)
- [money.js](https://github.com/openexchangerates/money.js/) by [Open Exchange Rates](https://github.com/openexchangerates/)
## How to Install
First, install the library in your project by npm:
```sh
$ npm install react-currency-hooks
```
Or Yarn:
```sh
$ yarn add react-currency-hooks
```
## Getting Started
**• Import hook in React application file:**
```js
import { useCurrency } from 'react-currency-hooks';
```
#### Params
| Name | Type | Default | Description |
| ----------- | ------ | ------- | -------------------------- |
| **amount** | number | ` ` | Amount of money to convert |
| **options** | {} | ` ` | Convertion options |
#### Options
| Name | Type | Default | Description |
| ----------------- | ------------------ | ------- | ------------------------------------------------------------------------- |
| **from** | string | ` ` | Currency to be converted |
| **to** | string or string[] | ` ` | The currency to which it is converted |
| **base** | string | ` ` | Base currency |
| **rates** | Rates | `{}` | Currency rates |
| **keepPrecision** | boolean | `true` | `true` (return exact values), `false` (return values rounded to 2 places) |
#### Returned Values
| Type | Description |
| ----------------------------------------------- | --------------- |
| number or object with currencies passed in `to` | Converted value |
## Example
```js
import React from 'react';
import { useCurrency } from 'react-currency-hooks';
const App = () => {
const rates = {
GBP: 0.92,
EUR: 1.0,
CHF: 1.08,
USD: 1.12,
};
/*
* 1. With single `to` value
*/
const currency = useCurrency(200, {
from: 'USD',
to: 'CHF',
base: 'EUR',
rates,
});
return
USD to CHF: {currency}
;
/*
* 2. With multiple `to` values
*/
const { chf, gbp } = useCurrency(200, {
from: 'USD',
to: ['CHF', 'GBP'],
base: 'EUR',
rates,
});
return (
<>
USD to CHF: {chf}
USD to GBP: {gbp}
>
);
};
export default App;
```
## License
This project is licensed under the MIT License © 2020-present Jakub Biesiada