-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a reddit-card component #262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome 👍 There are just 2 little things we can change before merge. :)
Otherwise good job.
const [fetched, setFetched] = useState(false); | ||
const data = async () => { | ||
const res = await axios.get( | ||
"https://www.reddit.com/r/CompanyOfHeroes/top.json?limit=50&t=week", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to swap axios with fetch ? That we we don't need to include extra lib
I think code like this should work:
const response = await fetch("https://www.reddit.com/r/CompanyOfHeroes/top.json?limit=50&t=week" );
const responseData = await response.json()
setpostData(responseData?.data?.children);
Fetch is modern request lib in native JS https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Now it's finally also in NodeJS (but only 18+)
So we don't need to include axios in the web projects anymore.
.filter(function (e: any) { | ||
return e?.data?.link_flair_text === "CoH2"; | ||
}) | ||
.slice(0, 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the filter and slice into the data function. In case something would trigger re-render of the component. These (filter and slice) would be run too. When we move it , it won't be run because it will be already saved in the state.
I have made the requested changes, please re-review the PR @petrvecera. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
I created a new card that displays the top 10 posts from Reddit from the past week.
It displays the number of upvotes, user, date, image, and title on which onClick opens the Reddit post.
Closes issue #254