Skip to content

0xOptimism/use-eth-price

Repository files navigation

use-eth-price

a custom React hook that provides ETH price

NPM JavaScript Style Guide

Install

npm install --save use-eth-price

Usage

To use the useEthPrice hook, you can import it into your React component and call it with a string argument that specifies the currency for which you want to get the ETH price. The hook will default to USD if you don't pass anything.

import React from "react";
import { useEthPrice } from "use-eth-price";

const App = () => {
  const { ethPrice, loading, error } = useEthPrice("sek");

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error..</p>;
  }

  if (ethPrice) {
    return <div>The price of ETH in SEK is: {ethPrice}</div>;
  }

  return null;
};

export default App;

License

MIT © 0xOptimism