I have created a dataStore.js
object and tried to pass below string to object as below.
Getting undefined while console.log in Home.js, could someone please advise the issue here.
let dataStore = {
globaldata1: {},
globaldata2: {}
}
export { dataStore }
// profile.js
let datastore = require("../global/dataStore");
let myStr1 = "This is a string" ;
let myStr2 = "This is another string" ;
datastore.globaldata1 = myStr1;
datastore.globaldata2 = myStr2;
// home.js
let datastore = require("../global/dataStore");
let globalStr1 = datastore.globaldata1 ;
console.log("Print the data::"+globalStr1);
let globalStr2 = datastore.globaldata2 ;
console.log("Print the second data::"+globalStr2);
It would seem the issue here is that you didn't properly capitalize your import.
Your export from dataStore.js is:
export { dataStore }
Where the S is capitalized, but in your Home.js:
const { datastore } = reqiure(...)
It doesn't have a capitalized S which would make the import undefined because dataStore.js doesn't export datastore, it exports dataStore