Open parthh1112 opened 10 months ago
Now check: because adding new Features like Reset Button https://github.com/AliGates915/React-Basic-Projects/tree/main/currency-converter/src
import { useState } from 'react' import {Input} from '../components/index' import useCurrencyInfo from '../hooks/useCurrencyInfo'
function CurrencyConvertor() {
const [amount, setAmount] = useState() const [from, setFrom] = useState("usd") const [to, setTo] = useState("inr") const [convertedAmount, setConvertedAmount] = useState(0)
const currencyInfo = useCurrencyInfo(from)
const options = Object.keys(currencyInfo)
const swap = () => { setFrom(to) setTo(from) setConvertedAmount(amount) setAmount(convertedAmount) }
const convert = () => { setConvertedAmount(amount * currencyInfo[to]) }
return (
<div
className="w-full h-screen flex flex-wrap justify-center items-center bg-cover bg-no-repeat"
style={{
backgroundImage: url('https://images.pexels.com/photos/3532540/pexels-photo-3532540.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2')
,
}}
sameekshaagupta commented 5 months agosameekshaagupta commented 5 months agoalso there was some error in input box.try using this code `
<InputBox label="From" amount={amount} currencyOptions={options} onCurrencyChange={(currency) => setFrom(currency)} selectCurrency={from} onAmountChange={(amount) => setAmount(amount)} /><div className="w-full mt-1 mb-4"> <InputBox label="To" amount={convertedAmount} currencyOptions={options} onCurrencyChange={(currency) => setTo(currency)} selectCurrency={to} amountDisable onAmountChange={(amount) => setAmount(amount)} /> </div>`
AliGates915 commented 5 months agosetFrom(currency)} selectCurrency={from} onAmountChange={(amount) => setAmount(amount)} /> <div className="relative w-full h-0.5"> <button type="button" className="absolute left-1/2 -translate-x-1/2 -translate-y-1/2 border-2 border-white rounded-md bg-blue-600 text-2xl text-white px-2 py-0.5" onClick={swap} >Swap </button> </div> <div className="w-full mt-1 mb-4"> <InputBox label="To" amount={convertedAmount} currencyOption={options} onCurrencyChange={(currency) => setTo(currency)} selectCurrency={to} amountDisable /> </div>
"Try run this code at the last after the amountDisable no need to add other line of code."
AliGates915 commented 5 months agonew api link:https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/${currency}.json
"Your API works on localhost and can be used anywhere. However, I am unable to access your API because it is not open."
AliGates915 commented 5 months agohttps://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json Now @sameekshaagupta this API is working perfectly, you change ${currency} instead of usd.
https://github.com/hiteshchoudhary/chai-aur-react/issues/125#issue-2321704449
"From Currency Type" box is showing the options of different currency but when we are selecting the option it is not changing it remain on USD option only
i have resolve this bug you can check it from here
https://github.com/parthh1112/React/tree/main/11CustomHookCurrencyConverter/src