0.25.2 • Published 2 years ago

@0xflair/react-crypto-prices v0.25.2

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Flair SDK: react-crypto-prices

React components and hooks to get prices of cryptocurrency coins and tokens from CoinGecko.

Getting Started

Installation

  1. Install the package:

    npm install @0xflair/react-crypto-prices
  2. Install peer dependencies:

    npm install axios
    
    # if visual components needed:
    npm install tailwindcss @headlessui/react @heroicons/react @tailwindcss/aspect-ratio
  3. Configure tailwind.config.js (Tailwind v3) to scan SDK for classes (if visual components needed):

    module.exports = {
      purge: [
        "./public/**/*.html",
        "./src/**/*.{js,jsx,ts,tsx,vue}",
    
        // This line tells Tailwind to look into SDK files
        "./node_modules/@0xflair/**/*.{js,jsx,ts,tsx,vue}",
      ],
      content: ["./src/**/*.{js,jsx,ts,tsx}"],
      plugins: [
        // These plugins are used in this package
        require("@tailwindcss/forms"),
        require("@tailwindcss/aspect-ratio"),
      ],
    };
  4. Configure the React provider:

    const cryptoPricesConfig = {
      coinGecko: {
        apiKey: "xxxx",
        symbols: ["ethereum", "matic-network"],
      },
    };
    
    const App = () => {
      return (
        <div className="app">
          <CryptoPricesProvider config={cryptoPricesConfig}>
            <HookExample />
          </CryptoPricesProvider>
        </div>
      );
    };

Usage

Simple Price

import { CryptoPrice, CryptoUnits } from "@0xflair/react-crypto-prices";

function App() {
  return (
    <>
      <CryptoPrice value='0.06' unit={CryptoUnits.ETHER} />
    </>
  );

Price Hook

import { useCryptoPrice } from "@0xflair/react-crypto-prices";

function App() {
  const [{data, error, loading}, fetchPrice] = useCryptoPrice({
    symbol: 'ethereum'
  });

  return (
    <ul>
        <li>Price of Ether: {data.usd} USD</li>
        <li>Loading: {loading ? 'Yes...' : 'Idle'}</li>
        <li>Error: {error}</li>
    </ul>
  );
0.25.2

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.24.2

2 years ago

0.24.1

2 years ago

0.24.0

2 years ago

0.23.0

2 years ago

0.22.2

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.21.3

2 years ago

0.21.2

2 years ago

0.21.1

2 years ago

0.21.0

2 years ago

0.20.1

2 years ago

0.20.0

2 years ago

0.19.3

2 years ago

0.19.2

2 years ago

0.19.1

2 years ago

0.19.0

2 years ago

0.18.1

2 years ago

0.18.0

2 years ago

0.17.1

2 years ago

0.17.0

2 years ago

0.16.2

2 years ago

0.16.1

2 years ago

0.16.0

2 years ago

0.15.0

2 years ago

0.14.4

2 years ago

0.14.3

2 years ago

0.14.2

2 years ago

0.14.1

2 years ago

0.14.0

2 years ago

0.13.3

2 years ago

0.13.2

2 years ago

0.13.1

2 years ago

0.13.0

2 years ago

0.12.3

2 years ago

0.12.2

2 years ago

0.12.1

2 years ago

0.12.0

2 years ago

0.11.14

2 years ago

0.11.13

2 years ago

0.11.12

2 years ago

0.11.11

2 years ago

0.11.10

2 years ago

0.11.9

2 years ago

0.11.8

2 years ago

0.11.7

2 years ago

0.11.6

2 years ago

0.11.5

2 years ago

0.11.4

2 years ago

0.11.3

2 years ago

0.11.2

2 years ago

0.11.1

2 years ago

0.11.0

2 years ago

0.10.2

2 years ago

0.10.1

2 years ago

0.10.0

2 years ago

0.9.7

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

2 years ago