Skip to content
Advertisement

Fetched Object from API doesn’t appear in mapping

I call a get request to my api, and then register them to my state with this:

JavaScript

I even tried the axios approach:

JavaScript

If I console.log posts_data and posts, it gives me the Object I got from my api:

JavaScript

But whenever I iterate and display it:

JavaScript

It doesn’t show up on the page. I even tried adding that random string there asdjasdljaskldjs and it doesn’t show too. The data is received and stored, but I wonder why it doesn’t display.

Entire component code

JavaScript

I also noticed when I console.log the posts_data or posts, it keeps printing over and over again while you’re on the page. Is that normal? enter image description here

Advertisement

Answer

Your mapping function isn’t returning the JSX. Change your return to:

JavaScript

You need to surround the returned JSX with parens, not {}, or you need a return before the {}.

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