When I am accessing const value of a js file from my another js file am getting undefined Data
Abc.js
import { Platform } from 'react-native';
const abc = Platform.select({
ios: [
'com.abc',
'com.xyz'
],
android: [
'com.pqr',
'com.lmn'
]
});
export default abc
App.js
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
Button,
View
} from 'react-native';
import { abc } from "./Abc";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
onPressgetData = () => {
console.warn("DATA " + JSON.stringify(abc));
}
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
!! Welcome to React Native !!
</Text>
<Button title="get Data"
color="#841584"
onPress={() => onPressgetData()} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
I am accessing abc const data from my App.js when I click get Data instead of array I am getting undefined in warning. I don't know where I have mistaken Thank you in advance
You've exported your module as default
and importing it as a named import
, therefore it is undefined.
Change
import { abc } from "./Abc";
to
import abc from "./Abc";
to get correct result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With