-
Notifications
You must be signed in to change notification settings - Fork 25
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
Shay Mashiah's React version for Countries assigment #11
base: main
Are you sure you want to change the base?
Shay Mashiah's React version for Countries assigment #11
Conversation
import CountryFlag from './CountryFlag'; | ||
import CountryInfo from './CountryInfo.jsx'; | ||
|
||
const Card = (country) => { |
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 convention is to use props to describe the argument that passed to the component.
const Card = (props) => {
Another way to do it is to use destruct and specify the arguments in the props.
const Card = ({name, flag, population, capital, region}) => {
@@ -0,0 +1,9 @@ | |||
const CountryFlag = (country) => { |
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.
As same as before (countries -> props / {...})
|
||
const Card = (country) => { | ||
return ( | ||
<Link to={`/details/${country.name}`} |
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.
save the route /details
as a const variable in a const.js
file and use it here
src/components/Header.jsx
Outdated
<header className='header'> | ||
<div className="container"> | ||
<div className="logo"> | ||
<Link to={'/'}> |
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.
save the home page route /
as a const variable in const.js
and use it here
/* display: flex; | ||
place-items: center; */ |
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.
remove the comment
src/pages/Home.jsx
Outdated
import Header from "../components/Header"; | ||
import Card from "../components/Card"; | ||
import { useState } from 'react'; | ||
import data from "../assets/CountriesData.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.
Use fetch and useEffect to retrieve the data from the api.
src/pages/Home.jsx
Outdated
|
||
|
||
const dropDownListClicked = () => { | ||
const dropDown = document.getElementsByClassName('dropdown-wrapper')[0]; |
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.
In React we try to avoid using document.get...
because we have a virtual DOM (There is a way to do it in react with useRef
but it is for very unique cases. we will probably talk about it in the next semester).
Try to do it with useState that indicates the dropdown state (open/close)
src/pages/Home.jsx
Outdated
} else { | ||
setFilteredData(data.filter((country) => country.region == region)); | ||
} | ||
document.getElementsByClassName('filter-by-region-txt')[0].innerText = region; |
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.
Same as before, we don't apply manipulations directly on the element, We will define a state or pass a prop which will indicate to React engine to re-render the page.
<ul> | ||
<li onClick={() => handleRegionFilter('All')}>All</li> | ||
<li onClick={() => handleRegionFilter('Africa')}>Africa</li> | ||
<li onClick={() => handleRegionFilter('Americas')}>America</li> | ||
<li onClick={() => handleRegionFilter('Asia')}>Asia</li> | ||
<li onClick={() => handleRegionFilter('Europe')}>Europe</li> | ||
<li onClick={() => handleRegionFilter('Oceania')}>Oceania</li> | ||
</ul> |
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.
Use map
function to render all elements.
const regions = ["all", "africa"] // more
const dropDownElements = regions.map(region => <li key={region} onClick={() => handleRegionFilter(region)}> {region} </li>)
src/pages/Home.jsx
Outdated
{filteredData.map((country) => ( | ||
<Card | ||
key={country.name} | ||
{...country} | ||
/> | ||
))} |
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.
Nice!
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.
Nice job. Please see my comments
No description provided.