0

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

2 Answers 2

1

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"
Sign up to request clarification or add additional context in comments.

Comments

1

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.