I have this piece of code
import axios from 'axios';
import {
CURRENCY_RATE,
CURRENCY_FETCHING,
CURRENCY_ERROR
} from './type.js';
import {
CurrencyRateLink
} from '../urls.js';
import {currencyDetails} from './currencyDetails'
export const CurrencyRate = (selectedCurrency) => {
return function (dispatch) {
dispatch({type: CURRENCY_FETCHING})
axios.get(CurrencyRateLink).then((response) => {
let Currency = []
if ( selectedCurrency != "USD") {
let CurrencyRates = Object.keys(response.data.rates)
for (let i=0; i<CurrencyRates.length; i++) {
if (selectedCurrency == CurrencyRates[i]) {
console.log("inside If condition")
let currencySymbol = currencyDetails[selectedCurrency][symbol]
console.log(currencySymbol)
Currency.push({
currencyName : CurrencyRates[i],
currencyPrice : response.data.rates[selectedCurrency]
})
}
}
}
return (
dispatch({
//Dispatching Redux Action
})
)}).catch((error) => dispatch({
//Error Handling
}))
}
Here this statement isn't logging anything
console.log(currencySymbol)
but a statement just above it is logging in console log
console.log("inside If condition")
[Question:] What could be doing wrong?
[Note:] When I do something like let currencySymbol = currencyDetails[selectedCurrency]
there currencyDetails[selectedCurrency]
may not exist but then shouldn't it log undefined or throw an error instead of not logging anything?
[Update:] I am working on React-native