a custom React hook that provides ETH price
npm install --save use-eth-price
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;
MIT © 0xOptimism