由于Async函数总是返回Promise,我们必须解决它才能获取其值。我需要导出它的值(返回的对象),以便我们可以在另一个模块中使用它。
export const getClient = async () => {
return await HttpService.getValueFromSettings('durl').then((response) => {
if(isValidResponse(response)) {
endpoint = response.data;
export const client = createClient(response.data);
//This is where getting error that we can not export in side the function
}
}
})
}
我需要在另一个模块中使用客户端。
我尝试在调用之前声明和初始化客户端对象,但是没有成功:
export let client = null;
export const getClient = async () => {
return await HttpService.getValueFromSettings('durl').then((response) => {
if(isValidResponse(response)) {
endpoint = response.data;
client = createClient(response.data);
return client;
}
}
})
}