-
Notifications
You must be signed in to change notification settings - Fork 0
adding Fetch and async functions #3
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
base: main
Are you sure you want to change the base?
Conversation
ahmagdy
left a comment
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.
Good work. Added comments about async/await usage
|
|
||
| //fetching the recipes and rendering them | ||
| let builtInRecipes = [] | ||
| async function getRecipes() { |
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.
try to add try catch to avoid having a failure when you receive an unexpected response or when you're unable to parse the output as json
| const response = await fetch(source); | ||
| builtInRecipes = await response.json(); | ||
| const allRecipes = getAllRecipes(); | ||
| renderRecipeCard(recipesContainer, getAllRecipes()); |
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.
The function is called getRecipes while you renderRecipeCard here. So, the name doesn't match the job of the function.
Remember that the function should have a single job.
I suggest that you call renderRecipeCard after calling getRecipes
| renderRecipeCard(recipesContainer, getAllRecipes()); | ||
| return allRecipes | ||
| } | ||
| getRecipes(); |
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.
an async function should be called with await. I don't see any await.
See https://dmitripavlutin.com/javascript-fetch-async-await/
and https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Dear Mentor,
This is the initial commit with the fetch and async function.
I am still wrapping my head around the concepts and getting a better grasp.
Still no frontend elements and I apologize for that.
I will keep trying to optimise the code while awaiting your feedback, because there are some elements that repeat and others that I feel are redundant, and that of course is not good.
Thank you again for your precious help.
S. I.