Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

514
Views
React - How to export an array from a JS file by making axios call and use it in another JS file?

I basically have 2 files named a.js and b.js.

b.js is building an array by making an axios call to an API to get some data and depending on that data the array is populated accordingly.I have to make b.js return that array so that I can use it in a.js

It is to be noted that when making the axios call in b.js I have to provide the user's authentication token as parameter.

In b.js

const b = () => {

//Getting the user authentication token
const [token, setToken] = userSessionStorage('details' null)
  
  var myarray = []
  
  useEffect(() => {
  
    //Making axios call to get data
    //depending on data building the array
    //As parameter to the axios call I am sending the user's authentication 
    
    //axios call
    //condition was what was get from the call
    
    if(condition){
        myarray.push(data1)
    }
    else{
        myarray.push(data2)
    }
    
    
    return myarray
    
  });
  
  
}

export default b

In a.js

import b  from "./b.js";

console.log(b) <-------------- GETTING UNDEFINED

Any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check if a.js and b.js are on the same level. Rest everything looks fine.

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!