Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

515
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda