【发布时间】:2021-11-18 11:24:03
【问题描述】:
我基本上有两个名为 a.js 和 b.js 的文件。
b.js 正在通过对 API 进行 axios 调用来获取一些数据来构建一个数组,并根据该数据相应地填充该数组。我必须让 b.js 返回该数组,以便我可以在其中使用它一个.js
需要注意的是,在 b.js 中进行 axios 调用时,我必须提供用户的身份验证 令牌作为参数。
在 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
在 a.js 中
import b from "./b.js";
console.log(b) <-------------- GETTING UNDEFINED
任何帮助将不胜感激。
【问题讨论】:
标签: javascript reactjs function import react-router