首页 > 解决方案 > React Native fetch API错误 - 页面不断刷新

问题描述

我正在尝试将此api 提取到我的 android 应用程序中。但是,模拟器屏幕一直在加载。有人可以指出错误吗?

校验码

标签: apireact-native

解决方案


componentDidMount正在返回而不处理 Promise。

无论如何,您不必退回任何东西componentDidMount。所以你可以有

componentDidMount() {
 fetch(...).then(res => res.json()).then((jsonRes) => {})
}

或者使用异步/等待


推荐阅读