I have defined some const on Color.js, but some of the Color is undefined when i call it on Screen.js
I use react-native 0.45 for this project. Here's the code i wrote :
Color.js
export const ATHENS_GRAY = '#EDEEF0';
export const AQUA_SPRING = '#F8FBFD';
export const BLACK = '#000000';
export const BRIGHT_TURQUOISE = '#1BC1F1';
export const CATSKILL_WHITE = '#E4ECF4';
export const FROLY = '#F68181';
export const FUN_BLUE = '#1B61AD';
export const HIT_GRAY = '#A3AEB9';
export const JUMBO = '#7C7D80';
export const LIMED_SPRUCE = '#3D474C';
Screen.js
import React, {Component} from 'react';
import { View, Text, FlatList, StyleSheet } from 'react-native';
import * as Color from './Color';
export default class Screen extends Component {
constructor(props) {
super(props);
console.log(Color.BRIGHT_TURQUOISE);
console.log(Color.FUN_BLUE);
}
render() {
return (<View/>)
}
}
The result of the console.log :
Color.BRIGHT_TURQUOISE is undefined
Color.FUN_BLUE is '#1B61AD'
Do you have any idea to solve this problem?
I have try it on my terminal using react-native log-android
,
and both values are obtained like this :
enter image description here
Or maybe you can try another way to export your constant on your Color.js
like this :
module.exports = Object.freeze({
ATHENS_GRAY : '#EDEEF0',
AQUA_SPRING : '#F8FBFD',
BLACK : '#000000',
BRIGHT_TURQUOISE : '#1BC1F1',
CATSKILL_WHITE : '#E4ECF4',
FROLY : '#F68181',
FUN_BLUE : '#1B61AD',
HIT_GRAY : '#A3AEB9',
JUMBO : '#7C7D80',
LIMED_SPRUCE : '#3D474C',
});
And you can try again :)
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