Reputation: 255
How can I use the 'const a' variable here in another file?
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Animated, Dimensions } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import colorsdata from '../../assets/data/colorsdata';
const { width, height } = Dimensions.get("window");
const a = colorsdata[0].word
Upvotes: 0
Views: 54
Reputation: 1888
Export it. Like this:
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Animated, Dimensions } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import colorsdata from '../../assets/data/colorsdata';
const { width, height } = Dimensions.get("window");
const a = colorsdata[0].word
export { a };
Then import it. Like this:
import { a } from "./Path_or_FileName"
Upvotes: 1
Reputation: 11
You can export a variable like so
export const a = colorsdata[0].word
to make it available outside its file. Then you can use it in another file by importing it using your file's path:
import { a } from "./path-to-file"
Upvotes: 1