简体   繁体   中英

import variable in React native

i am storing values into three different variable.

const companyValue = useSelector((state) => state.changeCompanyReducer.company);
const selectionValueArray = Object.values(companyValue);
const companyCode = selectionValueArray[0];
const employeeId = selectionValueArray[1];

i am getting 3 values from selectionValueArray , companyCode , employeeId .

i want to place whole code in one file and import all these three variable name anywhere i want so that i can get 3 different values.

How can i achieve this?Thanks.

You can do something like this

export const companyValue = your value
export const selectionValueArray = some value

Now you have to import like

import {companyValue, selectionValueArray} from './yourfile'

This type of import and export is called named export and import.
Learn more about it here

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM