File size: 610 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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);
};
|