Skip to content
Advertisement

Accessing object in returned promise using fetch w/ react js

I have this function:

JavaScript

Which returns this in the console:

Promise {[[PromiseStatus]]: “pending”, [[PromiseValue]]: undefined}

proto [[PromiseStatus]] : “resolved”

JavaScript

I need to access the name/value pairs in the object but I can’t get to them. I’m assuming I need to take one extra step after I convert the response to json but can’t figure it out. If anyone could help it would be greatly appreciated!

Advertisement

Answer

response.json() returns a promise, so you also need to handle it appropriately, eg:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement