【发布时间】:2022-11-25 17:44:24
【问题描述】:
我使用的是 react-redux,在我已经为新页面/编辑页面实现逻辑的 saga 文件中,我需要实现一个 API 来为客户获取一些代码。
const getCodesById = (Id) => get(`${BASE_URL}/${companyId}/codes`);
export function* getTableById(action) {
const Id = yield select(getCurrentCustomeId);
getEarningCodesForCompany(companyId).then((response) => {
console.log(response) //It shows correct array of objects from api
return response;
});
}
在console.log(response) 我可以正确地看到数据。
但是,我不知道如何在该函数外部的某个变量中提取该响应,以便能够在函数getTableById 中使用它。
我尝试使用 const request = yield call(getCodesById(Id));,但使用 yield 我的程序崩溃了。
我怎样才能做到这一点,获得回应并在其他地方使用它?
【问题讨论】:
标签: javascript reactjs react-redux