0
Goal:
I’m trying to make an array of objects containing 3 information: id
, title
and imageUri
. But when taking the value of imageUri
firebase(a download URL), the foreach hangs.
Error:[Unhandled Promise rejection: Typeerror: JSON.stringify cannot serialize Cyclic Structures.]
observing: When I take back the firebase part(imageUri: firebase...
), works as expected
the function:
processData = ( data ) => {
console.log('---------data recebida na processData(Main.js:70)--------\n', data)
var localProcessedData = [];
Object.entries(data).forEach( ([key, value]) => {
var event = {
id: key,
title: Object.getOwnPropertyDescriptor(value, "eventTitle").value,
imageUri: firebase.storage().ref('events/active/' + key + '/image').getDownloadURL()
}
localProcessedData.push(event);
})
this.setState({
processedData: localProcessedData,
eventsDataIsLoaded: true,
})
}
the type of data the function takes as a parameter:
Object {
"-M-I83aV9t1fezOsBn17": Object {
"active": true,
"created": "2020-02-05T02:18:30.772Z",
"description": "Olimpiadas Inter Atletica",
"eventTitle": "oia",
"location": "Uberlandia",
"owner": "p87xn6x8DZTwb6qyTadhkk3UxJV2",
"price": "130",
"startDate": "15",
"time": "14",
"updated": "2020-02-05T02:18:30.772Z",
},
"-M-KlUH-zQhnIhb6wMH8": Object {
"active": true,
"created": "2020-02-05T14:34:20.399Z",
"description": "Cia 2020",
"eventTitle": "Cia",
"location": "Uberlandia",
"owner": "p87xn6x8DZTwb6qyTadhkk3UxJV2",
"price": "130340",
"startDate": "15",
"time": "14",
"updated": "2020-02-05T14:34:20.399Z",
}
}
My goal is to format this data and turn it into an array like this:
Array [
Object {
"id": "-M-I83aV9t1fezOsBn17",
"title": "oia",
"imageUri": "url da imagem"
},
Object {
"id": "-M-KlUH-zQhnIhb6wMH8",
"title": "Cia",
"imageUri": "url da imagem"
}
]
Give it here https://stackoverflow.com/questions/42266462/react-native-json-stringify-cannot-serialize-cyclical-structures
– LeAndrade
@Leandrade I had read it earlier but I didn’t understand it very well
– Joao Pedro Oliveira
the function
getDownloadUrl
don’t return a Promise? or I’m wrong?– Leandro Simões
@Leandrosimões yes
– Joao Pedro Oliveira
Then, in that case you would have to perform this function, get the result of it, through the
.then
and only then, with the result in hand, continues the function and creates the objectevent
. The way you’re doing there, the estateimageUri
of the objectevent
is not the url itself, but a Promise not "solved", I do not know if I could understand?– Leandro Simões