React Native fetch is not a function

5.5k views Asked by At

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

There are 1 answers

1
Colin Ramsay On BEST ANSWER

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.