-
Notifications
You must be signed in to change notification settings - Fork 8
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
Assignment w1 react HANNA MELNYK #6
base: main
Are you sure you want to change the base?
Assignment w1 react HANNA MELNYK #6
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.
Good implementation 👍
- Functionality to display products and filter by categories is implemented
- Use of state hook
- Copied fake data into
src
folder as instructed.
Requested improvements
- Clean up the displayed product names and category names
- Improve folder structure by moving components into a folder called
components
. This structure improves maintainability. It's good to be able to recognise the difference between pages (stand alone) and components (re-usable)
import { ProductList } from './ProductList'; | ||
|
||
export const CategoryList = () => { | ||
const [selectedCategory, setSelectedCategory] = useState(null); // Initialize state with null to show all products |
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 use of state hook 👍
const handleCategoryClick = (category) => { | ||
if (selectedCategory === category) { | ||
// If the clicked category is already selected, deselect it | ||
setSelectedCategory(null); |
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 feature to toggle the selection on and off 👍
return ( | ||
<div> | ||
{/* Category selection buttons */} | ||
{categories.map((category, index) => ( |
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 could be a standalone component. Give it a try and see.
<div className="product-grid"> | ||
{filteredProducts.map((product) => ( | ||
<div key={product.id} className="product"> | ||
<img src={product.image} alt={product.title} /> |
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 practice to use the alt
attribute in web development 👍
{filteredProducts.map((product) => ( | ||
<div key={product.id} className="product"> | ||
<img src={product.image} alt={product.title} /> | ||
<h2>{product.title}</h2> |
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 FAKE:
from the displayed title.
onClick={() => handleCategoryClick(category)} // Handle category click | ||
className={selectedCategory === category ? 'active' : ''} | ||
> | ||
{category} |
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 FAKE:
from the category name.
Comments cleared! |
No description provided.