In my app, I have a huge constant array of string defined in allCurrency.js file as follows. The real array is much longer than the given array. I import it in my App.js file as import currecyData from './allCurrency'
. There is no syntax error. I can't access it in App.js. Just a warning import currecyData from './allCurrency'. How do I access in App.js. I don't want to bring the whole constant array in App.js. It will work, but it will be ugly.
const currecyData = [
"AED",
"ARS",
"AUD",
"BGN",
"BRL",
"BSD",
"CAD",
"CHF",
"CLP",
"CNY",
"COP",
"CZK",
"DKK",
"DOP",
"EGP",
"EUR",
"FJD",
"GBP"]
Either do an
export const currecyData = [
"AED",
"ARS",
"AUD",
"BGN",
"BRL",
"BSD",
"CAD",
"CHF",
"CLP",
"CNY",
"COP",
"CZK",
"DKK",
"DOP",
"EGP",
"EUR",
"FJD",
"GBP"]
And import it as
import {currecyData} from './allCurrency'
or add a default export in your allCurrency.js as obiwankenoobi commented:
export default currecyData;
const currecyData = [
"AED",
"ARS",
"AUD",
"BGN",
"BRL",
"BSD",
"CAD",
"CHF",
"CLP",
"CNY",
"COP",
"CZK",
"DKK",
"DOP",
"EGP",
"EUR",
"FJD",
"GBP"];export default currecyData;
You have to export the entity to import it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.