hiteshchoudhary / chai-aur-react

chai aur react series on youtube
5.98k stars 794 forks source link

currency-converter - Bug Fix (Incorrect Prop Update in <InputBox> Component) #141

Open sagarbendale2004 opened 1 week ago

sagarbendale2004 commented 1 week ago

### - Issue: Incorrect State Update on Currency Change

There is an issue with the component in the code where the onCurrencyChange prop is incorrectly updating the amount state instead of the currency state. This causes the amount to be updated instead of the selected currency when the currency is changed.

current code -

<InputBox
    label="From"
    amount={amount}
    currencyOptions={options}
    onCurrencyChange={(currency) => setAmount(amount)}
    selectCurrency={from}
    onAmountChange={(amount) => setAmount(amount)}
/>

The issue lies in the onCurrencyChange prop: onCurrencyChange={(currency) => setAmount(amount)}

The onCurrencyChange prop should correctly update the currency state. The corrected code should be -

<InputBox
    label="From"
    amount={amount}
    currencyOptions={options}
    onCurrencyChange={(currency) => setFrom(currency)}
    selectCurrency={from}
    onAmountChange={(amount) => setAmount(amount)}
/>