react-native - 使用 axios 进行昂贵的 api 调用会阻止可触摸,但在 react native 和 redux-saga 中不会使用 fetch
问题描述
我正在使用 redux saga 来处理反应原生应用程序中的 api 调用。这是使用 axios 时设置 saga 的方式:
function* getList(){
try{
response = yield call(axios.get,'https://example.com/list');
yield put({type:'LIST_RESULTS',data:response.data});
} catch(err){
console.log(err);
}
}
...
function* rootSaga(){
yield takeLatest(types.GET_LIST,getList);
...
}
该调用获取大约 700kbs 的数据。当这个动作被调度时,所有的可触摸对象都没有响应,一旦收到响应,所有在请求进行时调用的事件都会被批量触发。
与 fetch 一起使用时相同的 api 请求没有相同的问题。这是使用 fetch 时的代码
function* getList(){
try{
response = yield call(fetch,'https://example.com');
data = yield call(getJson,response);
yield put({type:'LIST_RESULTS',data});
} catch(err){
console.log(err);
}
}
async function getJson(data){
return new Promise((resolve,reject)=>{
data.json().then(result=>{
resolve(result);
}).catch(err=>{
reject(err);
});
});
}
任何人都可以帮我调试这里的问题吗?
解决方案
推荐阅读
- python - 比较两个数据集,找到相关性并进行校正/补偿
- javascript - 谷歌翻译,如何防止恢复原始语言
- html - 我无法将身体元素居中
- xml - CDC Wonder 数据集 API
- swiftui - 如何使用 SwiftUI 解码嵌套的 JSON 元素并在视图中显示信息?
- java - 我使用 mediacord 的应用程序被破坏了
- ssis - 通过 SSIS 处理 Azure 分析服务。错误:无法连接到远程服务器
- javascript - Javascript Timer 项目:为什么 clearInterval 不起作用?
- windows - 当我尝试复制和重命名 80K 文件时,XCOPY 崩溃。有没有更好的办法?
- javascript - 为什么我不能使用 nodemailer 和 nodejs 发送电子邮件?