使用 React Native 进行同步 http 请求 [英] Make synchronous http request with React Native

查看:64
本文介绍了使用 React Native 进行同步 http 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道同步请求不是一个好习惯,我总是尽量避免它们.但在这种情况下,我必须使用一个使用同步 http 请求的外部库,我不想修改第三方代码.

根据

有什么办法可以解决这个问题吗?

解决方案

我建议对 http 请求使用 fetch 和 async/await.XMLHttpRequest 同步在 javascript 世界中已弃用,所以它是本机反应

<块引用>

从 Gecko 30.0 开始(Firefox 30.0/Thunderbird 30.0/SeaMonkey2.27),由于对用户体验的负面影响,主线程上的同步请求已被弃用.

I know synchronous requests are not a good practice and I always try to avoid them. But in this case I must use an external library that uses synchronous http request and I don't want to get to the point of modifying third party code.

According to React Native DOCS, the XMLHttpRequest API is built in to React Native, but when i try to use it I get Synchronous http requests are not supported.

Is there any way to fix this?

解决方案

I would suggest using fetch with async/await for http requests. XMLHttpRequest synchronous is deprecated in the javascript world, so it is in react native

Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

这篇关于使用 React Native 进行同步 http 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆