I have two files that both need a global variable. I have a click button. When it's clicked, runs a function. The code looks like this:
file1:
var globalVar = '', // The global variable
<button onClick = {() => this.edit(arg1)}></button>
function edit (arg1){
globalVar = arg1;
}
module.exports = globalVar;
I have another file, looks like this:
file2:
var globalVar = require(./file1);
function openModal(){
if (globarVar != ''){
do something
} }
The issue is that when I click button, the globalVar is updated in the edit() function, but I console.log(globalVar) in file2 it shows ' '.My question is how do I pass the globalVar to file2 when I click the button?