Skip to content
Advertisement

Promise Returning Undefined When Setting State But Printing to Console Fine

So I’m quite new to web dev but I’m trying to build my first front-end app that simply fetches some data from an API and displays it. When I console.log() my promise, it returns an array of objects, which is what I want and what I expect from the promise. But, when I try to set my component’s state to that same promised array, React is throwing this error:

Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.

Here is the relevant code:

JavaScript

Any help with this would be appreciate!

Advertisement

Answer

I think there’s not actual data, but Promise.

How about trying this??

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