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.
Check if a.js and b.js are on the same level. Rest everything looks fine.