I have a state variable ( wallsJSON
) in react-native that is supposed to hold JSON data returned from the URL http://unsplash.it/list
So in my constructor/getInitialState I have the variable set up like this
{
wallsJSON : []
}
I am using the following function to fetch the json data
fetchWallsJSON() {
var url = 'http://unsplash.it/list';
fetch(url)
.then( response => response.json())
.then( jsonData => {
this.setState({
isLoading: false,
wallsJSON: jsonData
});
})
.catch( error => console.log('JSON Fetch error : ' + error) );
}
I am facing this error :
JSON Fetch error : TypeError: In this environment the target of assign MUST be an object.This error is a performance optimization and not spec compliant.
I tried using underscore to convert the returned data to Object using _.object
, also I tried simple wallsJson: Object(jsonData)
but none of which worked.