Skip to content

React2-Week1#5

Open
SathiC1990 wants to merge 4 commits into
mainfrom
React-2-Week-1
Open

React2-Week1#5
SathiC1990 wants to merge 4 commits into
mainfrom
React-2-Week-1

Conversation

@SathiC1990

Copy link
Copy Markdown
Owner

#Meal-Card Component

@villads-valur villads-valur left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey Sathi 👋
Good job on the implementation! It looks like you achieved everything needed for this task!
It would be great if you add a bit of description and possibly some screenshots to the PR description, that helps me as reviewer alot!
Let me know if you have any questions at all.

Comment thread app-next/components/Meal/Meal.js Outdated
@@ -0,0 +1,20 @@
import React from "react";
import styles from "./Meal.module.css";
export default function Meal({ meal }) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue(style): I would suggest writing out all of the props you need to pass to the component for it to render properly. Passing an object like this will make it re-render everytime the parent component does, as the reference to the object is not stable. This will cause unnecessary computations which is detrimental to performance.

Comment on lines +12 to +22
async function fetchMeals() {
try {
const response = await fetch(api("/meals"));
if (!response.ok) {
throw new Error("Failed to fetch meals");
}
const data = await response.json();
setMeals(data);
} catch (error) {
console.error("Error fetching meals:", error);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion(performance): I would move the definition of this function out of the useEffect. If you define it inside the useEffect, it would be defined everytime the useEffect is called - this is unnecessary computation which could cause performance issues.

const data = await response.json();
setMeals(data);
} catch (error) {
console.error("Error fetching meals:", error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: Instead of putting the error in the console, i would suggest saving the error in a state variable and using that to display some proper message or feedback to the user.

Comment on lines +30 to +38
{meals.length === 0 ? (
<p>No meals found</p>
) : (
<div className={styles.grid}>
{meals.map((meal) => (
<Meal key={meal.id} meal={meal} />
))}
</div>
)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Style: I would suggest breaking this ternary statement into a proper if-else statement instead. Where each branch of the if-else statement returns the content based on the different state. This makes it way clearer to read and reason what is returned by your component.

@SathiC1990

Copy link
Copy Markdown
Owner Author

Hi @villads-valur Thank you for your time reviewing my code .And
I have done the changes , as per your 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