Download react-crypto-tracker/src/CryptoContext.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 610 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/CryptoContext.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/CryptoContext.js
-
curl -L -o CryptoContext.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/CryptoContext.js
610 Bytes
| import React, { createContext, useContext, useEffect, useState } from "react"; | |
| const Crypto = createContext(); | |
| const CryptoContext = ({ children }) => { | |
| const [currency, setCurrency] = useState("INR"); | |
| const [symbol, setSymbol] = useState("₹"); | |
| useEffect(() => { | |
| if (currency === "INR") setSymbol("₹"); | |
| else if (currency === "USD") setSymbol("$"); | |
| }, [currency]); | |
| return ( | |
| <Crypto.Provider value={{ currency, setCurrency, symbol }}> | |
| {children} | |
| </Crypto.Provider> | |
| ); | |
| }; | |
| export default CryptoContext; | |
| export const CryptoState = () => { | |
| return useContext(Crypto); | |
| }; | |