Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

528
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda