Skip to content

Conversation

@Majoodeh
Copy link

No description provided.

@Majoodeh
Copy link
Author

@Majoodeh Majoodeh changed the title Week 3 React project Majd hussein React w3 Jan 16, 2026
Copy link

@robvk robvk left a comment

Choose a reason for hiding this comment

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

Nothing critical, the thing I do really want you to look at is the html doc manipulation as that is a mistake that shows a non-react mindset. Definitely change that in your version but I assume you can do that. The rest are sloppy mistakes to avoid in the future.

So will approve, but let me know if anything is unclear

getCategories();
}, []);

let buttonsArr = [];
Copy link

Choose a reason for hiding this comment

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

This can be a const

}, []);

let buttonsArr = [];
const buttonClick = (event) => {
Copy link

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 do any html doc manipulation. In line 53 you call this function, but there you already know the category that is being clicked. So you can actually pass the real category along to this function by writing onClick={() => buttonClick(category)}


export function FavoritesProvider({ children }) {
const [favorites, setFavorites] = useState([]);
function switchFavorite(itemId) {
Copy link

Choose a reason for hiding this comment

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

Small detail, in computer science jargon switch is generally the thing that facilitates the changing and toggle is actually changing it. So for example you could have a FavoriteSwitch component (the thing that handles to changing) and it would call a function toggleFavorite.

In this case you only have the context so this function should probably be called toggleFavorite

}

if (loading) {
return <Message message={"Products are loading..."} />;
Copy link

Choose a reason for hiding this comment

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

Nice work making a Message component to handle all of this, is very common!

if (error) {
return <Message message={error} />;
}
console.log(data);
Copy link

Choose a reason for hiding this comment

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

You forgot to remove a debugging console.log

setLoading(false);
}

console.log(data);
Copy link

Choose a reason for hiding this comment

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

Another debugging log line


function ProductCard({ item }) {
const { favorites, switchFavorite } = useContext(FavoritesContext);
const isProductFav = favorites.includes(item.id);
Copy link

Choose a reason for hiding this comment

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

You could think about putting the isFavorite function in the FavoritesContext as well as then any component using the FavoritesContext can use it if they want to

</div>
<div className="p-4 flex-grow">
<h6 className="mb-2 text-slate-800 text-lg font-semibold line-clamp-2">
{item.title.replace("Fake: ", "")}
Copy link

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 filter on Fake anymore

@robvk robvk added the Approved label Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants