-
Notifications
You must be signed in to change notification settings - Fork 28
Fetching from JSON and Filtering #5
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
Tamir198
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.
You don't need to explain your code by adding comments, the code should explain it self with meaningful names
| // Load countries from JSON file, once completed use displayCountries to render them | ||
| const loadCountries = async () => { | ||
| const grid = document.getElementById("countries-grid"); | ||
|
|
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.
Please save your hardcoded strings into constants file
| countries.forEach((country) => { | ||
| const countryElement = document.createElement("a"); | ||
| countryElement.href = "#"; | ||
| countryElement.className = "country scale-effect"; |
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.
Don't use innerHtmL, its a dangerous method.
| const filterCountries = async (region) => { | ||
| try { | ||
| const response = await fetch("./CountriesData.json"); | ||
| const countries = await response.json(); |
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.
This function should only do 1 thing and this is to filter the countries.
Extract the get data logic into separate function
| // Load countries when the DOM is fully loaded | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| loadCountries(); | ||
|
|
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.
This is a good practice to call dat fetching functions when the app first loads
No description provided.