相关疑难解决方法(0)

React Native:可能未处理的承诺拒绝

我收到以下错误: Possible unhandled promise rejection (id:0: Network request failed

这是承诺代码,我不知道这里有什么问题,任何想法?

  return fetch(url)
    .then(function(response){
      return response.json();
    })
    .then(function(json){
      return {
        city: json.name,
        temperature: kelvinToF(json.main.temp),
        description: _.capitalize(json.weather[0].description)
      }
    })
    .catch(function(error) {
    console.log('There has been a problem with your fetch operation: ' + error.message);
    });
}
Run Code Online (Sandbox Code Playgroud)

**编辑:我添加了一个catch函数并得到了更好的错误 You passed an undefined or null state object; instead, use forceUpdate(). index.ios.js:64 undefined

这是index.ios.js代码.网址很好,并给我正确的json数据.我可以用控制台日志中都可以看到region.latitude,并region.longitude处于可用Api(region.latitude, region.longitude).但是data未定义.我仍然不确定发生了什么,为什么会出现问题data以及为什么它未定义.

// var React = require('react-native'); --deprecated

// updated
import React from …
Run Code Online (Sandbox Code Playgroud)

react-native

49
推荐指数
2
解决办法
13万
查看次数

标签 统计

react-native ×1