-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
add task solution #2909
base: master
Are you sure you want to change the base?
add task solution #2909
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.
Thank you for your hard work on this project! 😊 While your implementation is mostly solid, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Data Preparation in Non-Root Components: The
TodoInfo.tsx
andUserInfo.tsx
components importusers
directly, which violates the guideline of preparing data in one place (the App component) and passing it down as props. This is an important best practice to ensure data consistency and maintainability. Please refactor these components to receive the necessary data as props from the parent component. -
Unique Key Prop: In
TodoList.tsx
, ensure that eachTodoInfo
component in themap
function has a uniquekey
prop. This is crucial for React's reconciliation process and helps prevent potential rendering issues. -
Missing Labels: The form fields in
App.tsx
lack associated labels. Adding labels is important for accessibility and usability, and it aligns with the task's requirement to add labels where needed.
These changes are necessary to meet the core requirements and ensure the functionality and maintainability of the code. Once these issues are addressed, your code will be in great shape! Keep up the good work, and feel free to reach out if you have any questions or need further assistance. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
}, | ||
})); | ||
|
||
const [todos, setTodos] = useState<todo[]>(editedTodos) |
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.
The useState
hook is used correctly to initialize the todos
state with editedTodos
. However, ensure that the todo
type imported from ./components/types
includes the user
property as optional, which is correctly done in the types.ts
file.
} | ||
|
||
const newTodo: todo = { | ||
id: Math.max(...todos.map(todo => todo.id)) + 1, |
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.
The calculation of the new id
for newTodo
is correct, but ensure that todos
is not empty to avoid errors with Math.max
. Consider adding a check or default value if todos
might be empty.
title: title, | ||
completed: false, | ||
userId: userId, | ||
user: usersFromServer.find(user => user.id === userId) || { |
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.
The logic to find the user by userId
is correct, but ensure that usersFromServer
is always available and populated to avoid potential runtime errors.
<option value="0" disabled> | ||
<select data-cy="userSelect" value={userId} onChange={ | ||
(event)=>{ | ||
setUserId(+event.target.value) |
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.
The setUserId
function uses +event.target.value
to convert the value to a number, which is correct. Ensure that the userId
is always a valid number to prevent unexpected behavior.
src/components/TodoInfo/TodoInfo.tsx
Outdated
@@ -1 +1,27 @@ | |||
export const TodoInfo = () => {}; | |||
import React from "react"; | |||
import users from "../../api/users"; |
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.
Importing users
directly in this component violates the checklist guideline: "Prepare data in one place (App component) and pass it to child components. Don't use import
keyword in non-root components". Consider passing the necessary user data as props from the parent component instead.
src/components/UserInfo/UserInfo.tsx
Outdated
@@ -1 +1,15 @@ | |||
export const UserInfo = () => {}; | |||
import React from "react"; | |||
import users from "../../api/users"; |
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.
The import of users
from ../../api/users
is unnecessary in this component. According to the checklist: "Prepare data in one place (App component) and pass it to child components. Don't use import
keyword in non-root components". You should remove this import as it is not used in the component.
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.
Great job on addressing the key issues in your code! 🎉 You've made significant improvements by ensuring that data is passed down as props, which aligns with best practices for data preparation and consistency. The unique key
prop for each TodoInfo
component is correctly implemented, enhancing React's reconciliation process.
However, there are still a few areas to refine:
- Data Preparation: Ensure that
usersFromServer
andtodosFromServer
are prepared in theApp
component and passed down as props to maintain consistency and improve maintainability. - User Data Propagation: The
user
type should be passed down as a prop rather than being imported directly in components likeUserInfo
. This will help maintain data consistency across your application.
These improvements will not only enhance the functionality of your code but also make it more robust and maintainable. Keep up the great work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
import usersFromServer from './api/users'; | ||
import todosFromServer from './api/todos'; |
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.
The usersFromServer
and todosFromServer
data should be prepared in the App component and passed down as props to child components. This ensures data consistency and maintainability. Consider refactoring to pass the necessary data as props.
</a> | ||
</article> | ||
</section> | ||
<TodoList todos={todos}/> |
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.
Ensure that each TodoInfo
component within the TodoList
has a unique key
prop. This is crucial for React's reconciliation process and helps prevent potential rendering issues.
import React from "react"; | ||
import { todo} from "../types"; | ||
import classNames from "classnames"; | ||
import { UserInfo } from "../UserInfo"; |
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.
The UserInfo
component should not be imported directly here. Instead, the user data should be passed down as a prop from the parent component to maintain data consistency and follow best practices. Consider refactoring to receive the user data as a prop.
@@ -1 +1,14 @@ | |||
export const UserInfo = () => {}; | |||
import React from "react"; | |||
import { user } from "../types"; |
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.
The user
type should be passed down as a prop from the parent component rather than being imported directly. This ensures data consistency and follows best practices. Consider refactoring to receive the user data as a prop.
https://shymdima.github.io/react_add-todo-form/