How to export a variable or a list which is modified inside a function inside the class to other .js file?
renderBoxContent = () => {
let total = 0;
let Total = 0;
let itemList = [];
let data = [];
this.state.availableItems.map((items)=> {
if(items.purchase > 0){
Total += items.price*items.purchase;
total = items.price*items.purchase;
console.log(items.purchase);
console.log(total);
data.push(
{
key: items.name,
name: items.name,
// src: items.image,
singlePrice: items.price.toFixed(2),
purchase: items.purchase,
totalItemPrice: total.toFixed(2),
}
)
}
})
//how to export 'data' to other .js file?
itemList.push( <Table defaultExpandAllRows={false} locale={{emptyText: 'Empty Cart'}} style={{background: '#ffffff'}} pagination={false} columns={column} dataSource={data} size="small" />)
itemList.push( <h3 style={{paddingLeft:15,paddingTop:20}}> Total {Total.toFixed(2)}</h3>)
return itemList;
}
Should be able to access and import the 'data' list variable in other .js file