React help - looping through the Reddit API

Hi I have been working and troubleshooting this for a couple of days now. What I want is to loop through the items I selected in my component and print them on the app (it will be searchable but that will be later) - I did this fine with another API so I decided to give the Reddit one a go.

I mapped correctly but nothing was showing up , so I looked at the JSON and made an if else loop but now I am getting an error (it may be in the wrong js file)

APP JS is below - I am torn between if I should loop by mapping OR with a while statement since mapping seemed to just get one array and I want all nested arrays.

Current Idea:

{ =>{

  while(i=0, i < 28, i++){

    /> });

previous: { =>

  /> )) }

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.


Not sure why you would need a while loop?

We need to know what data the API is returning and how you are getting it. We also need a bit more context about how you are using the data. If you can post a GitHub with your code or a Codesandbox with a live version you are more likely to get an answer.

1 Like