Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ShayMashiah
Copy link

No description provided.

@ShayMashiah ShayMashiah requested review from Tamir198 and GilHeller and removed request for Tamir198 December 29, 2024 15:30
import CountryFlag from './CountryFlag';
import CountryInfo from './CountryInfo.jsx';

const Card = (country) => {
Copy link
Contributor

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) => {
Copy link
Contributor

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}`}
Copy link
Contributor

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

<header className='header'>
<div className="container">
<div className="logo">
<Link to={'/'}>
Copy link
Contributor

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

Comment on lines +27 to +28
/* display: flex;
place-items: center; */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

import Header from "../components/Header";
import Card from "../components/Card";
import { useState } from 'react';
import data from "../assets/CountriesData.json";
Copy link
Contributor

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.



const dropDownListClicked = () => {
const dropDown = document.getElementsByClassName('dropdown-wrapper')[0];
Copy link
Contributor

@GilHeller GilHeller Jan 4, 2025

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)

} else {
setFilteredData(data.filter((country) => country.region == region));
}
document.getElementsByClassName('filter-by-region-txt')[0].innerText = region;
Copy link
Contributor

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.

Comment on lines +59 to +66
<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>
Copy link
Contributor

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>)

Comment on lines 74 to 79
{filteredData.map((country) => (
<Card
key={country.name}
{...country}
/>
))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@GilHeller GilHeller left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants