profidash_98 profidash_98 - 3 months ago 12
iOS Question

React-Native: Undefined is not an object although there is a decleration in front

In the following Code I have downloaded a JSON file.
Afterwards I take an Array of Dictionaries of it an passed it to downloadWebsiteData().
In this function it comes following Error:

Undefined is not an object (evaluating 'web files.length')

Here is my code I am using: IMPORTANT: webFiles is an Array!

downloadWebsiteData(webFiles) {

this.setState({amountOfAllWebsites: webFiles.length});

for(var ii = 0; ii < webFiles.length; ii++)

var urlToDownload = webFiles[ii].url;

fetch(urlToDownload, {method: "GET"}).then((responseData) => {

this.saveDataToLocalStorage(responseData, urlToDownload);
alert('Save: '+urlToDownload);

this.setState({actuallyLoadedWebsites: this.state.actuallyLoadedWebsites++});




If you look at this line this.downloadWebsiteData(); inside the fetch method in the code above. You are not passing any argument to the function downloadWebsiteData(). You need to pass in the list of links to the function there if you are intending to call it recursively.