I have just started the reddit client project today, and I have ran into a bit of an issue.
I am wanting so that when i click on the comments button the comments drop down, I have tried various different methods but cant get anything working and dont really know what to type into google, I will link my git repo and if anyone is able to take the time to help I will greatly appreciate it. Thanks.
Cool app idea! Iâm just diving into the world of React as well so I donât have a solution necessarily, but I think Iâve spotted your problem.
In your App.js file, youâre rendering the Post components with map method on the posts array. With each rendering, youâre giving the Post a prop called comments and assigning it to the post's data.num_comments. For your app, it looks like a good idea to be handing the Post components the num_comments, but if you inspect the JSON that youâre fetching from, you can see that num_comments is assigned to a integer and nothing else.
From inspecting the JSON, I canât see find any key/value pairs that could render the comments section. However, it does have one key called permalink that links directly to that post on reddit. Upon pressing the comments button in your app, you could possibly fetch another JSON file from that permalink that does contain a key assigned to the comments.
Post some sample code in a branch so we can see what you are doing. My initial guess is you want to have a new component called comments which has the css style feature display:none; Then when you click on a button it sets the display to visible. That way you can make the comments appear on a click.
I wouldnât make it any more complicated than that until you have it working. Then you can start thinking about dynamically loading the comments from Reddit or adding animations to make it appear maybe?
I am still trying to get my head around something. I noticed you passed in some code between curlbraces in your code.
I donât understand how does the code know where to find those props?
Hey, so a good way to a very simple explanation is from dec Edâs recipe app tutorial, you can pass props outside of app.js but canât pass them in from components? I could be wrong with that statement but thatâs my understanding
Hi Alex
I am still trying to get my head around exactly how the project gets the subreddits and number of subreddits from reddit.
Could you share a link to the webpage so I can review the code in chrome dev tools.
If you could explain what files are needed to get the content from the reddit api that would help alot.
It helps to learn when I can see some working examples and then reverse engineer the code to understand how things are done.
regards,
Hi patrick i have the app running on netlify, be aware images are super low res, which is something im going to go back and change but didnt want to get too hung up on this project, i think you might be able to use the dev tools to get a rough understanding, here is the link. https://redditminimalfirst.netlify.app/
It keeps coming with below error messages on my Chrome console:
"Access to fetch at âhttps://www.reddit.com/r/.jsonâ from origin âhttp://localhost:3000â has been blocked by CORS policy: No âAccess-Control-Allow-Originâ header is present on the requested resource. If an opaque response serves your needs, set the requestâs mode to âno-corsâ to fetch the resource with CORS disabled."