Comments

Peter Marreck

response here is a Promise object. response.json() is the JSON resolution of the promise, thus response.rooms will always be undefined. you have to pass it through an additional .then which return's response.json() and then the last "then" call here receives the json object, which .rooms will now be defined on

profile/avatar/default
Andreas

thanks a lot, this made it work! :)

profile/avatar/default
Jeffylube

.then((response) => { return response.json(); }) .then((response) => { // Get the rooms from the JSON: let rooms = response.rooms; // Mutate the state with "setState": this.setState({ rooms: rooms, messages: rooms[0].messages, }); })

Peter Marreck

I haven't done frontend in a while so I didn't know what a polyfill was; this seems like an explanation: https://remysharp.com/2010/10/08/what-is-a-polyfill