• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

208
Views
While retrieving the dataStore.js object throws undefined in js file

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);
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error