-
Notifications
You must be signed in to change notification settings - Fork 8
Eli_D_Rajha-w2-React #10
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
Live Netlify site for Week 2: |
week2/project/project-2/src/App.jsx
Outdated
<Route | ||
path="/" | ||
element={ | ||
<div> | ||
<h1>Ecommerce Shop</h1> | ||
|
||
{error && <p>Error fetching data!</p>} | ||
{loading ? ( | ||
<p>Loading...</p> | ||
) : ( | ||
<> | ||
<CategoryList | ||
categories={categories} | ||
selectedCategory={selectedCategory} | ||
onSelectCategory={setSelectedCategory} | ||
/> | ||
<ProductList products={products} /> | ||
</> | ||
)} | ||
</div> | ||
} | ||
/> |
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.
It works fine as is, but splitting it into a MainPage component might help keep things more organized, especially as the app grows.
<div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap', marginBottom: '20px' }}> | ||
{categories.map((cat, 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.
I recommend using CSS Modules or Tailwind CSS instead of inline styles
week2/project/project-2/src/App.jsx
Outdated
fetch(url) | ||
.then((res) => { | ||
if (!res.ok) throw new Error('Network response was not ok'); | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
setProducts(data); | ||
setLoading(false); | ||
}) | ||
.catch(() => { | ||
setError(true); | ||
setProducts([]); | ||
setLoading(false); | ||
}); |
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 this case, it is better to use finally
to ensure the loading state with more readable and maintain reason
padding: '8px 12px', | ||
}} | ||
> | ||
{cat} |
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.
{cat} | |
{category} | |
Using category
instead of cat
would be a small change in length, but it greatly improves readability. Especially collaborative with team project.
https://fakestoreapi.com/products/categories
-> To get all the categorieshttps://fakestoreapi.com/products
orhttps://fakestoreapi.com/products/category/:selectedCategory
-> To get the products. The API needs to do the filtering, not the frontend. Usually the amount of products will be too large to do the filtering on the frontend./product/:id
whenever you click on the product card in the list. This should get the details from the endpoint:https://fakestoreapi.com/products/<id>
. For now we won't add a navigation bar, the browsers 'back' button will do the trick. TIP: You will need to add thereact-router-dom
package and add the routing to your app regardless.