React Native fetch is not a function

扶醉桌前 提交于 2019-12-24 03:07:36

问题


I'm trying to use react native for a simple app. I want to download a json array from a page and display it as a listview. I'm doing this

var listApp = React.createClass({

fetchData : function() {
  fetch(requestURL)
    .then((response) => response.json())
    .then((responseData) => {
      console.log(responseData);
    })
    .done();
},
componentDidMount: function() {
  this.fetchData();
  this.setState({
    dataSource: this.state.dataSource.cloneWithRows(elements)
  });
},

But doing this I get the error fetch is not a function from Chrome debugger. I get fetch in this way var fetch = require("fetch");


回答1:


You don't need to require it. It's a polyfill for the browser version, and like the browser version it's always available to the global scope.



来源:https://stackoverflow.com/questions/30954899/react-native-fetch-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!